Created the error.ts middleware
This commit is contained in:
parent
d7949eabc3
commit
49bce43abe
10
api/middlewares/error.ts
Normal file
10
api/middlewares/error.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import {Request, Response, NextFunction} from "express";
|
||||||
|
|
||||||
|
module.exports = ((err: Error | undefined, req: Request, res: Response, next: NextFunction) => {
|
||||||
|
if (err instanceof SyntaxError) {
|
||||||
|
return res.status(500).send({ message: err.message });
|
||||||
|
} else if (err) {
|
||||||
|
return res.status(500).json({message: "An internal error occurred"});
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user