From 39d45dc11b2388c65018f793fddf4936e6b68fdb Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Fri, 7 Mar 2025 22:31:55 +0100 Subject: [PATCH] refactor(error_handlers): use existing NotFoundError class also gets rid of "any" type :-) --- src/routes/error_handlers.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/routes/error_handlers.ts b/src/routes/error_handlers.ts index e773fcb22..c570a9dbd 100644 --- a/src/routes/error_handlers.ts +++ b/src/routes/error_handlers.ts @@ -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); });