2020-02-05 02:27:46 +07:00
|
|
|
export enum HttpCode {
|
|
|
|
Ok = 200,
|
|
|
|
Redirect = 302,
|
|
|
|
NotFound = 404,
|
|
|
|
BadRequest = 400,
|
|
|
|
Unauthorized = 401,
|
|
|
|
LargePayload = 413,
|
|
|
|
ServerError = 500,
|
|
|
|
}
|
|
|
|
|
2020-11-06 06:07:51 +07:00
|
|
|
/**
|
|
|
|
* Represents an error with a message and an HTTP status code. This code will be
|
|
|
|
* used in the HTTP response.
|
|
|
|
*/
|
2020-02-05 02:27:46 +07:00
|
|
|
export class HttpError extends Error {
|
2020-11-06 06:07:51 +07:00
|
|
|
public constructor(message: string, public readonly status: HttpCode, public readonly details?: object) {
|
2020-02-05 02:27:46 +07:00
|
|
|
super(message)
|
|
|
|
this.name = this.constructor.name
|
|
|
|
}
|
|
|
|
}
|