2021-06-03 03:36:25 +00:00
|
|
|
import {ErrorWithContext, HTTPStatus, HTTPMessage} from '../util'
|
2021-03-08 16:07:10 +00:00
|
|
|
|
2021-03-25 13:50:13 +00:00
|
|
|
/**
|
|
|
|
* An error class that has an associated HTTP status.
|
|
|
|
*
|
|
|
|
* When thrown inside the request lifecycle, this will result in the HTTP
|
|
|
|
* status code being applied to the response.
|
|
|
|
*/
|
2021-03-08 16:07:10 +00:00
|
|
|
export class HTTPError extends ErrorWithContext {
|
|
|
|
constructor(
|
|
|
|
public readonly status: HTTPStatus = 500,
|
2021-06-03 03:36:25 +00:00
|
|
|
public readonly message: string = '',
|
2021-07-08 01:13:23 +00:00
|
|
|
context?: {[key: string]: any},
|
2021-03-08 16:07:10 +00:00
|
|
|
) {
|
2021-07-08 01:13:23 +00:00
|
|
|
super('HTTP ERROR', context)
|
2021-03-08 16:07:10 +00:00
|
|
|
this.message = message || HTTPMessage[status]
|
|
|
|
}
|
|
|
|
}
|