add error & error handler middleware

This commit is contained in:
X4Lo committed 2024-05-17 11:50:37 +01:00
1 parent c9881b5558
commit 76c4e47a38
8 files changed
+100

No files matched your search

+13
View File
@@ -0,0 +1,13 @@
const CustomError = require('./CustomError');
class ConflictError extends CustomError {
constructor(message) {
super(message);
}
statusCode() {
return 409; // Conflict
}
}
module.exports = ConflictError;
+13
View File
@@ -0,0 +1,13 @@
class CustomError extends Error {
constructor(message) {
super(message);
this.name = this.constructor.name;
Error.captureStackTrace(this, this.constructor);
}
statusCode() {
return 500; // Default to 500 Internal Server Error
}
}
module.exports = CustomError;
+13
View File
@@ -0,0 +1,13 @@
const CustomError = require('./CustomError');
class ForbiddenError extends CustomError {
constructor(message) {
super(message);
}
statusCode() {
return 403; // Forbidden
}
}
module.exports = ForbiddenError;
+13
View File
@@ -0,0 +1,13 @@
const CustomError = require('./CustomError');
class InternalServerError extends CustomError {
constructor(message) {
super(message);
}
statusCode() {
return 500; // Internal Server Error
}
}
module.exports = InternalServerError;
+13
View File
@@ -0,0 +1,13 @@
const CustomError = require('./CustomError');
class NotFoundError extends CustomError {
constructor(message) {
super(message);
}
statusCode() {
return 404; // Not Found
}
}
module.exports = NotFoundError;
+13
View File
@@ -0,0 +1,13 @@
const CustomError = require('./CustomError');
class UnauthorizedError extends CustomError {
constructor(message) {
super(message);
}
statusCode() {
return 401; // Unauthorized
}
}
module.exports = UnauthorizedError;
+13
View File
@@ -0,0 +1,13 @@
const CustomError = require('./CustomError');
class ValidationError extends CustomError {
constructor(message) {
super(message);
}
statusCode() {
return 400; // Bad Request
}
}
module.exports = ValidationError;