Skip to content

Instantly share code, notes, and snippets.

@shafiimam
Created May 29, 2023 16:35
Show Gist options
  • Save shafiimam/f2310e971ce2db46c4bf70a2502528f9 to your computer and use it in GitHub Desktop.
Save shafiimam/f2310e971ce2db46c4bf70a2502528f9 to your computer and use it in GitHub Desktop.
express error handler middlware
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