diff --git a/src/errors/http_error.ts b/src/errors/http_error.ts new file mode 100644 index 000000000..2ab806d8b --- /dev/null +++ b/src/errors/http_error.ts @@ -0,0 +1,13 @@ +class HttpError extends Error { + + statusCode: number; + + constructor(message: string, statusCode: number) { + super(message); + this.name = "HttpError"; + this.statusCode = statusCode; + } + +} + +export default HttpError; \ No newline at end of file diff --git a/src/errors/not_found_error.ts b/src/errors/not_found_error.ts index ae97a6ac5..44f718a2c 100644 --- a/src/errors/not_found_error.ts +++ b/src/errors/not_found_error.ts @@ -1,10 +1,12 @@ -class NotFoundError extends Error { - statusCode: number; +import HttpError from "./http_error.js"; + +class NotFoundError extends HttpError { + constructor(message: string) { - super(message); + super(message, 404); this.name = "NotFoundError"; - this.statusCode = 404; } + } export default NotFoundError; diff --git a/src/errors/validation_error.ts b/src/errors/validation_error.ts index 35eb5897d..25cdd509e 100644 --- a/src/errors/validation_error.ts +++ b/src/errors/validation_error.ts @@ -1,9 +1,10 @@ -class ValidationError extends Error { - statusCode: number; +import HttpError from "./http_error.js"; + +class ValidationError extends HttpError { + constructor(message: string) { - super(message) + super(message, 400) this.name = "ValidationError"; - this.statusCode = 400; } }