mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-11 11:02:27 +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 {
|
import HttpError from "./http_error.js";
|
||||||
statusCode: number;
|
|
||||||
|
class NotFoundError extends HttpError {
|
||||||
|
|
||||||
constructor(message: string) {
|
constructor(message: string) {
|
||||||
super(message);
|
super(message, 404);
|
||||||
this.name = "NotFoundError";
|
this.name = "NotFoundError";
|
||||||
this.statusCode = 404;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default NotFoundError;
|
export default NotFoundError;
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
class ValidationError extends Error {
|
import HttpError from "./http_error.js";
|
||||||
statusCode: number;
|
|
||||||
|
class ValidationError extends HttpError {
|
||||||
|
|
||||||
constructor(message: string) {
|
constructor(message: string) {
|
||||||
super(message)
|
super(message, 400)
|
||||||
this.name = "ValidationError";
|
this.name = "ValidationError";
|
||||||
this.statusCode = 400;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user