Files
comment-api/src/middleware/errorHandler.js
2025-11-23 20:04:00 +03:00

18 lines
444 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
export const errorHandler = (err, req, res, next) => {
// eslint-disable-next-line no-console
console.error('Hata:', err);
const status = err.status || 500;
const code = err.code || 'INTERNAL_ERROR';
const message = err.message || 'Sunucu hatası';
const response = {
error: {
code,
message
}
};
if (err.details) {
response.error.details = err.details;
}
return res.status(status).json(response);
};