mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-10 02:02:29 +08:00
refactor(error_handlers): use existing NotFoundError class
also gets rid of "any" type :-)
This commit is contained in:
parent
d8ce385134
commit
39d45dc11b
@ -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);
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user