0
0
mirror of https://github.com/honojs/hono.git synced 2024-11-29 09:43:20 +01:00
hono/deno_dist/http-exception.ts
Yusuke Wada 03df736763 feat(utils): remove HTTP status messages from http-status.ts (#1037)
* feat(utils): remove HTTP status messages from `http-status.ts`

* denoify
2023-04-28 12:10:20 +09:00

26 lines
573 B
TypeScript

import type { StatusCode } from './utils/http-status.ts'
type HTTPExceptionOptions = {
res?: Response
message?: string
}
export class HTTPException extends Error {
readonly res?: Response
readonly status: StatusCode
constructor(status: StatusCode = 500, options?: HTTPExceptionOptions) {
super(options?.message)
this.res = options?.res
this.status = status
}
getResponse(): Response {
if (this.res) {
return this.res
}
return new Response(this.message, {
status: this.status,
statusText: this.message,
})
}
}