Initial commit
Next.js + Express event management app for Hope Family Church.
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
const { safeErrorMessage } = require('../utils/errorUtils');
|
||||
|
||||
// Not found error handler — don't echo the URL back (leaks route structure)
|
||||
const notFound = (req, res, next) => {
|
||||
const error = new Error('Not Found');
|
||||
res.status(404);
|
||||
next(error);
|
||||
};
|
||||
|
||||
// General error handler
|
||||
const errorHandler = (err, req, res, next) => {
|
||||
const statusCode = res.statusCode === 200 ? 500 : res.statusCode;
|
||||
|
||||
res.status(statusCode).json({
|
||||
message: safeErrorMessage(err),
|
||||
stack: process.env.NODE_ENV === 'production' ? undefined : err.stack,
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = { notFound, errorHandler };
|
||||
Reference in New Issue
Block a user