|
|
|
@ -1,5 +1,6 @@
|
|
|
|
import type { Application, NextFunction, Request, Response } from "express";
|
|
|
|
import type { Application, NextFunction, Request, Response } from "express";
|
|
|
|
import log from "../services/log.js";
|
|
|
|
import log from "../services/log.js";
|
|
|
|
|
|
|
|
import NotFoundError from "../errors/not_found_error.js";
|
|
|
|
|
|
|
|
|
|
|
|
function register(app: Application) {
|
|
|
|
function register(app: Application) {
|
|
|
|
app.use((err: any, req: Request, res: Response, next: NextFunction) => {
|
|
|
|
app.use((err: any, req: Request, res: Response, next: NextFunction) => {
|
|
|
|
@ -16,8 +17,7 @@ function register(app: Application) {
|
|
|
|
|
|
|
|
|
|
|
|
// catch 404 and forward to error handler
|
|
|
|
// catch 404 and forward to error handler
|
|
|
|
app.use((req, res, next) => {
|
|
|
|
app.use((req, res, next) => {
|
|
|
|
const err = new Error(`Router not found for request ${req.method} ${req.url}`);
|
|
|
|
const err = new NotFoundError(`Router not found for request ${req.method} ${req.url}`);
|
|
|
|
(err as any).status = 404;
|
|
|
|
|
|
|
|
next(err);
|
|
|
|
next(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|