Fix 404 handler

This commit is contained in:
Madeline 2022-11-05 21:59:12 +11:00
parent 4cb6c2639f
commit 4469acd390

View File

@ -74,15 +74,16 @@ export class FosscordServer extends Server {
path.join(__dirname, "routes", "/"), path.join(__dirname, "routes", "/"),
); );
// 404 is not an error in express, so this should not be an error middleware
// this is a fine place to put the 404 handler because its after we register the routes
// and since its not an error middleware, our error handler below still works.
api.use( api.use(
"*", "*",
(error: any, req: Request, res: Response, next: NextFunction) => { (req: Request, res: Response, next: NextFunction) => {
if (error) return next(error);
res.status(404).json({ res.status(404).json({
message: "404 endpoint not found", message: "404 endpoint not found",
code: 0, code: 0,
}); });
next();
}, },
); );