0
0
mirror of https://github.com/honojs/hono.git synced 2024-11-30 01:56:18 +01:00
hono/deno_dist/http-exception.ts
Alexander Kozlov 8387b8c0f6
fix(HttpException): error message should not be the HTTP reason phrase (#1161)
* fix(HttpException): error message should not be the HTTP reason phrase

* review fixes

---------

Co-authored-by: Nasa <nasa@mail.inc>
2023-06-07 21:17:52 +09:00

25 lines
541 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,
})
}
}