2024-04-01 13:28:43 +07:00
|
|
|
import HttpStatus from "./http-status";
|
|
|
|
|
|
2024-04-03 16:13:29 +07:00
|
|
|
type DevMessage =
|
|
|
|
|
| "missing_or_invalid_parameter"
|
|
|
|
|
| "data_exists"
|
|
|
|
|
| "data_in_used"
|
|
|
|
|
| "no_permission"
|
|
|
|
|
| "unknown_url"
|
|
|
|
|
| "data_not_found"
|
|
|
|
|
| "unauthorized";
|
2024-04-02 15:43:33 +07:00
|
|
|
|
2024-04-01 13:28:43 +07:00
|
|
|
class HttpError extends Error {
|
|
|
|
|
/**
|
|
|
|
|
* HTTP Status Code
|
|
|
|
|
*/
|
|
|
|
|
status: HttpStatus;
|
|
|
|
|
message: string;
|
2024-04-02 15:43:33 +07:00
|
|
|
devMessage?: DevMessage;
|
2024-04-01 13:28:43 +07:00
|
|
|
|
2024-04-02 15:43:33 +07:00
|
|
|
constructor(status: HttpStatus, message: string, devMessage?: DevMessage) {
|
2024-04-01 13:28:43 +07:00
|
|
|
super(message);
|
|
|
|
|
|
|
|
|
|
this.name = "HttpError";
|
|
|
|
|
this.status = status;
|
|
|
|
|
this.message = message;
|
2024-04-02 15:26:37 +07:00
|
|
|
this.devMessage = devMessage;
|
2024-04-01 13:28:43 +07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default HttpError;
|