lib/src/http/HTTPError.ts

19 lines
562 B
TypeScript
Raw Normal View History

2021-06-03 03:36:25 +00:00
import {ErrorWithContext, HTTPStatus, HTTPMessage} from '../util'
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.
*/
export class HTTPError extends ErrorWithContext {
constructor(
public readonly status: HTTPStatus = 500,
2021-06-03 03:36:25 +00:00
public readonly message: string = '',
context?: {[key: string]: any},
) {
super('HTTP ERROR', context)
this.message = message || HTTPMessage[status]
}
}