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:
parent
eb4be67c89
commit
306c87fca2
10 changed files with 315 additions and 19 deletions
22
src/utils/AppError.js
Normal file
22
src/utils/AppError.js
Normal 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;
|
||||
Loading…
Add table
Add a link
Reference in a new issue