Created
August 28, 2022 09:10
-
-
Save arifsetyawan/7cfc88ae485dce68b677633e4e85e7e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Request, Response, NextFunction } from "express"; | |
import { CustomError } from "../errors/custom-error"; | |
export const errorHandler = ( | |
err: Error, | |
req: Request, | |
res: Response, | |
next: NextFunction | |
) => { | |
if (err instanceof CustomError) { | |
return res.status(err.statusCode).send({ errors: err.serializeError() }); | |
} | |
res.status(400).send({ | |
errors: [{message: 'something went wring'}] | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment