refactor(error_handlers): use existing NotFoundError class

also gets rid of "any" type :-)
This commit is contained in:
Panagiotis Papadopoulos 2025-03-07 22:31:55 +01:00
parent d8ce385134
commit 39d45dc11b

View File

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