2025-03-29 00:31:25 +01:00
|
|
|
class AppError extends Error {
|
|
|
|
constructor(statusCode, message) {
|
|
|
|
super(message);
|
|
|
|
this.statusCode = statusCode;
|
|
|
|
|
2025-03-30 17:31:21 +02:00
|
|
|
if (statusCode.toString().startsWith("4")) {
|
|
|
|
this.status = "Fail";
|
2025-03-29 00:31:25 +01:00
|
|
|
} else {
|
2025-03-30 17:31:21 +02:00
|
|
|
this.status = "Error";
|
2025-03-29 00:31:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.tryCatch = (controller) => async (req, res, next) => {
|
|
|
|
try {
|
|
|
|
await controller(req, res, next);
|
|
|
|
} catch(err) {
|
|
|
|
next(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = AppError;
|