mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-10 10:22:29 +08:00
refactor(errors): add HttpError class and extend existing errors from it
This commit is contained in:
parent
39d45dc11b
commit
2c91f6e7bc
13
src/errors/http_error.ts
Normal file
13
src/errors/http_error.ts
Normal file
@ -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;
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user