mirror of
https://github.com/codex-team/codex.docs.git
synced 2025-07-21 14:19:42 +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:
parent
09835e3007
commit
05f8f0d9e1
6 changed files with 57 additions and 19 deletions
|
@ -14,10 +14,6 @@ class Aliases {
|
||||||
public static async get(aliasName: string): Promise<Alias> {
|
public static async get(aliasName: string): Promise<Alias> {
|
||||||
const alias = await Alias.get(aliasName);
|
const alias = await Alias.get(aliasName);
|
||||||
|
|
||||||
if (!alias.id) {
|
|
||||||
throw new Error('Entity with given alias does not exist');
|
|
||||||
}
|
|
||||||
|
|
||||||
return alias;
|
return alias;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
import express, { Request, Response } from 'express';
|
import express, { Request, Response } from 'express';
|
||||||
import Aliases from '../controllers/aliases.js';
|
import Aliases from '../controllers/aliases';
|
||||||
import Pages from '../controllers/pages.js';
|
import Pages from '../controllers/pages';
|
||||||
import Alias from '../models/alias.js';
|
import Alias from '../models/alias';
|
||||||
import verifyToken from './middlewares/token.js';
|
import verifyToken from './middlewares/token';
|
||||||
import PagesFlatArray from '../models/pagesFlatArray.js';
|
import PagesFlatArray from '../models/pagesFlatArray';
|
||||||
|
import HttpException from '../exceptions/httpException';
|
||||||
|
|
||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
|
@ -24,7 +26,7 @@ router.get('*', verifyToken, async (req: Request, res: Response) => {
|
||||||
const alias = await Aliases.get(url);
|
const alias = await Aliases.get(url);
|
||||||
|
|
||||||
if (alias.id === undefined) {
|
if (alias.id === undefined) {
|
||||||
throw new Error('Alias not found');
|
throw new HttpException(404, 'Alias not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (alias.type) {
|
switch (alias.type) {
|
||||||
|
@ -46,11 +48,18 @@ router.get('*', verifyToken, async (req: Request, res: Response) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
res.status(400).json({
|
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,
|
success: false,
|
||||||
error: err,
|
error: err,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
export default router;
|
export default router;
|
|
@ -1,7 +1,10 @@
|
||||||
{% extends 'layout.twig' %}
|
{% extends 'layout.twig' %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
|
<div class="error-page">
|
||||||
|
<h1>
|
||||||
|
┬┴┬┴┤ {{status}} ├┬┴┬┴
|
||||||
|
</h1>
|
||||||
<h1>{{message}}</h1>
|
<h1>{{message}}</h1>
|
||||||
<h2>{{error.status}}</h2>
|
</div>
|
||||||
<pre>{{error.stack}}</pre>
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
29
src/frontend/styles/components/error.pcss
Normal file
29
src/frontend/styles/components/error.pcss
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
.error-page {
|
||||||
|
font-size: 15px;
|
||||||
|
text-align: center;
|
||||||
|
position: absolute;
|
||||||
|
top: 45%;
|
||||||
|
left: 50%;
|
||||||
|
|
||||||
|
@media (--mobile) {
|
||||||
|
position: relative;
|
||||||
|
top: 30vh;
|
||||||
|
left: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (--tablet) {
|
||||||
|
position: relative;
|
||||||
|
top: 30vh;
|
||||||
|
left: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
@media (--mobile) {
|
||||||
|
font-size: 20px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
p {
|
||||||
|
margin: 40px 0 20px;
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,6 +8,7 @@
|
||||||
@import './components/page.pcss';
|
@import './components/page.pcss';
|
||||||
@import './components/landing.pcss';
|
@import './components/landing.pcss';
|
||||||
@import './components/auth.pcss';
|
@import './components/auth.pcss';
|
||||||
|
@import './components/error.pcss';
|
||||||
@import './components/button.pcss';
|
@import './components/button.pcss';
|
||||||
@import './components/sidebar.pcss';
|
@import './components/sidebar.pcss';
|
||||||
@import './components/navigator.pcss';
|
@import './components/navigator.pcss';
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue