1
0
Fork 0
mirror of https://github.com/codex-team/codex.docs.git synced 2025-08-09 15:35:25 +02:00

aliases not found added

This commit is contained in:
Umang G. Patel 2022-09-01 20:48:47 +05:30
parent 2c9a6324c4
commit 8502c5cb70

View file

@ -4,6 +4,7 @@ import Pages from '../controllers/pages';
import Alias from '../models/alias';
import verifyToken from './middlewares/token';
import PagesFlatArray from '../models/pagesFlatArray';
import HttpException from '../exceptions/httpException';
const router = express.Router();
@ -24,7 +25,7 @@ router.get('*', verifyToken, async (req: Request, res: Response) => {
const alias = await Aliases.get(url);
if (alias.id === undefined) {
throw new Error('Alias not found');
throw new HttpException(404, 'Alias not found');
}
switch (alias.type) {
@ -46,11 +47,18 @@ router.get('*', verifyToken, async (req: Request, res: Response) => {
}
}
} catch (err) {
res.status(404).render('error', {
message: 'Page not found',
status: 404,
});
if (err instanceof HttpException && err.status === 404) {
res.status(404).render('error', {
message: 'Page not found',
status: 404,
});
} else {
res.status(500).json({
success: false,
error: err,
});
}
}
});
export default router;
export default router;