Files
Checkmate/Server/middleware/handleErrors.js
T

22 lines
626 B
JavaScript
Raw Normal View History

2024-10-15 11:57:37 +08:00
import logger from "../utils/logger.js";
2025-01-30 00:41:31 +03:00
import ServiceRegistry from "../service/serviceRegistry.js";
import StringService from "../service/stringService.js";
2024-05-27 10:47:14 -07:00
const handleErrors = (error, req, res, next) => {
2024-10-17 12:07:30 +08:00
const status = error.status || 500;
2025-01-30 00:41:31 +03:00
const stringService = ServiceRegistry.get(StringService.SERVICE_NAME);
const message = error.message || stringService.friendlyError;
const service = error.service || stringService.unknownService;
2024-10-24 15:28:13 +08:00
logger.error({
message: message,
2024-10-17 12:07:30 +08:00
service: service,
method: error.method,
2024-10-24 15:28:13 +08:00
stack: error.stack,
2024-10-17 12:07:30 +08:00
});
res.error({
status,
msg: message,
});
2024-05-27 10:47:14 -07:00
};
2024-10-15 11:57:37 +08:00
export { handleErrors };