Created
May 29, 2023 16:35
-
-
Save shafiimam/f2310e971ce2db46c4bf70a2502528f9 to your computer and use it in GitHub Desktop.
express error handler middlware
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
const ErrorHandler = (err, req, res, next) => { | |
console.log('Middleware Error Hadnling'); | |
const errStatus = err.statusCode || 500; | |
const errMsg = err.message || 'Something went wrong'; | |
res.status(errStatus).json({ | |
success: false, | |
status: errStatus, | |
message: errMsg, | |
stack: process.env.NODE_ENV === 'development' ? err.stack : {}, | |
}); | |
}; | |
export default ErrorHandler; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment