Send http 404 when algorithm not found
This commit is contained in:
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user