
- Updated `.env` and added `.env.test` for environment variables. - Introduced API documentation in `API_DOCUMENTATION.md`. - Added authentication setup guide in `AUTHENTICATION_SETUP.md`. - Implemented user authentication with JWT and email verification. - Created new routes for user management and form submissions. - Added middleware for API key authentication and error handling. - Set up Redis for rate limiting and notifications. - Removed obsolete files and configurations related to the previous Rust implementation.
32 lines
765 B
JavaScript
32 lines
765 B
JavaScript
const logger = require("../config/logger");
|
|
|
|
const errorHandler = (err, req, res, next) => {
|
|
logger.error(err.message, {
|
|
stack: err.stack,
|
|
path: req.path,
|
|
method: req.method,
|
|
});
|
|
|
|
// If the error is a known type, customize the response
|
|
// Otherwise, send a generic server error
|
|
if (err.isOperational) {
|
|
// You can add an 'isOperational' property to your custom errors
|
|
res.status(err.statusCode || 500).json({
|
|
error: {
|
|
message: err.message,
|
|
code: err.errorCode || "INTERNAL_SERVER_ERROR",
|
|
},
|
|
});
|
|
} else {
|
|
// For unexpected errors, don't leak details to the client
|
|
res.status(500).json({
|
|
error: {
|
|
message: "An unexpected error occurred.",
|
|
code: "INTERNAL_SERVER_ERROR",
|
|
},
|
|
});
|
|
}
|
|
};
|
|
|
|
module.exports = errorHandler;
|