1 | import { BaseController } from "./base.controller";
|
2 | import Request from "./request";
|
3 | import Response from "./response";
|
4 | import { isProduction } from "./app";
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | export default class ErrorController extends BaseController {
|
12 | |
13 |
|
14 |
|
15 |
|
16 |
|
17 | public async onNotFound(req: Request): Promise<Response> {
|
18 | if (req.lynx && req.lynx.route && req.lynx.route.isAPI) {
|
19 | throw this.error(404, 'not found');
|
20 | }
|
21 | return this.render("lynx/404", req);
|
22 | }
|
23 |
|
24 | |
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 | public async onError(error: Error, req: Request): Promise<Response> {
|
31 | let e = error as any;
|
32 | if (!e.statusCode) {
|
33 | e.statusCode = 500;
|
34 | }
|
35 | if (req.lynx && req.lynx.route && req.lynx.route.isAPI) {
|
36 | throw this.error(e.statusCode, error.message);
|
37 | }
|
38 | return this.render("lynx/error", req, {
|
39 | error: error,
|
40 | isProduction: isProduction()
|
41 | });
|
42 | }
|
43 | }
|