feat: Error handling middleware

feat: Ability to get the db variable from everywhere with getDatabase function
feat: Hello world when getting root url
fix: Now mods model is able to communicate with db
fix: fixed a syntax error in routes/mods.js file which caused sending two responses to the client
This commit is contained in:
Gu://em_ 2025-03-29 00:31:25 +01:00
parent eb4be67c89
commit 306c87fca2
10 changed files with 315 additions and 19 deletions

22
src/utils/AppError.js Normal file
View file

@ -0,0 +1,22 @@
class AppError extends Error {
constructor(statusCode, message) {
super(message);
this.statusCode = statusCode;
if (status_code.ToString().startsWith("4")) {
this.status = "fail";
} else {
this.status = "error";
}
}
}
exports.tryCatch = (controller) => async (req, res, next) => {
try {
await controller(req, res, next);
} catch(err) {
next(err);
}
}
module.exports = AppError;