提交 0ffee2e5 编写于 作者: J Jason Park

Send http 404 when algorithm not found

上级 f025e882
......@@ -56,16 +56,22 @@ app.use((req, res) => {
const [, categoryKey, algorithmKey] = url.parse(req.originalUrl).pathname.split('/');
let { title, description } = packageJson;
const algorithm = hierarchy.find(categoryKey, algorithmKey);
if (algorithm) {
title = [algorithm.categoryName, algorithm.algorithmName].join(' - ');
description = algorithm.description;
let algorithm = undefined;
if (categoryKey && categoryKey !== 'scratch-paper') {
algorithm = hierarchy.find(categoryKey, algorithmKey) || null;
if (algorithm) {
title = [algorithm.categoryName, algorithm.algorithmName].join(' - ');
description = algorithm.description;
} else {
res.status(404);
}
}
const indexFile = res.indexFile
.replace(/\$TITLE/g, title)
.replace(/\$DESCRIPTION/g, description)
.replace(/\$ALGORITHM/g, algorithm ? JSON.stringify(algorithm).replace(/</g, '\\u003c') : 'undefined');
.replace(/\$ALGORITHM/g, algorithm === undefined ? 'undefined' :
JSON.stringify(algorithm).replace(/</g, '\\u003c'));
res.send(indexFile);
});
......
......@@ -148,6 +148,9 @@ class App extends BaseComponent {
if (window.__PRELOADED_ALGORITHM__) {
this.props.setAlgorithm(window.__PRELOADED_ALGORITHM__);
delete window.__PRELOADED_ALGORITHM__;
} else if (window.__PRELOADED_ALGORITHM__ === null) {
delete window.__PRELOADED_ALGORITHM__;
return Promise.reject(new Error('Algorithm Not Found'));
} else if (categoryKey && algorithmKey) {
return AlgorithmApi.getAlgorithm(categoryKey, algorithmKey)
.then(({ algorithm }) => this.props.setAlgorithm(algorithm));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册