Skip to content

Commit

Permalink
✨ feat(middlewares): error handler
Browse files Browse the repository at this point in the history
  • Loading branch information
EvandroCalado committed Feb 20, 2024
1 parent 20babdb commit e0e0919
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions middlewares/errorHandlerMiddleware.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { StatusCodes } from "http-status-codes";

const errorHandlerMiddleware = (err, req, res, next) => {
const statusCode = err.statusCode || StatusCodes.INTERNAL_SERVER_ERROR;
const msg = err.message || "Something went wrong, try again later";

res.status(statusCode).json({ msg });
};

export default errorHandlerMiddleware;

0 comments on commit e0e0919

Please sign in to comment.