Skip to content

Commit

Permalink
Add custom error handler middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin-Quinn51 committed Nov 22, 2024
1 parent 98075c6 commit 4399c9c
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/errors/errorHandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { NextFunction, Request, Response } from "express";

const errorHandler = (
err: any,
req: Request,
res: Response,
next: NextFunction,
) => {
const statusCode = err.statusCode || 500;
const errMsg = err.message || "Something went wrong";

res.status(statusCode).json({
success: false,
status: statusCode,
message: errMsg,
});
};

export { errorHandler };

0 comments on commit 4399c9c

Please sign in to comment.