mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-10 18:39:22 +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 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);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user