Skip to content

Instantly share code, notes, and snippets.

@arifsetyawan
Created August 28, 2022 09:10
Show Gist options
  • Save arifsetyawan/7cfc88ae485dce68b677633e4e85e7e0 to your computer and use it in GitHub Desktop.
Save arifsetyawan/7cfc88ae485dce68b677633e4e85e7e0 to your computer and use it in GitHub Desktop.
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