1
0
Fork 0
mirror of https://github.com/codex-team/codex.docs.git synced 2025-08-03 20:45:24 +02:00

404 Page not found added (#225)

* replace repose of aliases with error page

* error twig modified with proper messages

* add the error pcss

* the lint removed

* centered the error message

* center style added independent of screen

* the top position changed

* aliases not found added

* aliases throw removed

* Update src/backend/controllers/pages.ts

Co-authored-by: Peter Savchenko <specc.dev@gmail.com>

Co-authored-by: Peter Savchenko <specc.dev@gmail.com>
This commit is contained in:
Umang G. Patel 2022-09-02 00:24:33 +05:30 committed by GitHub
parent 09835e3007
commit 05f8f0d9e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 57 additions and 19 deletions

View file

@ -1,9 +1,11 @@
import express, { Request, Response } from 'express';
import Aliases from '../controllers/aliases.js';
import Pages from '../controllers/pages.js';
import Alias from '../models/alias.js';
import verifyToken from './middlewares/token.js';
import PagesFlatArray from '../models/pagesFlatArray.js';
import Aliases from '../controllers/aliases';
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 +26,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 +48,18 @@ router.get('*', verifyToken, async (req: Request, res: Response) => {
}
}
} catch (err) {
res.status(400).json({
success: false,
error: err,
});
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;