deno.land / x / hono@v4.2.5 / http-exception.ts

http-exception.ts
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import type { StatusCode } from './utils/http-status.ts'
type HTTPExceptionOptions = { res?: Response message?: string cause?: unknown}
/** * `HTTPException` must be used when a fatal error such as authentication failure occurs. * @example * ```ts * import { HTTPException } from 'hono/http-exception' * * // ... * * app.post('/auth', async (c, next) => { * // authentication * if (authorized === false) { * throw new HTTPException(401, { message: 'Custom error message' }) * } * await next() * }) * ``` * @see https://hono.dev/api/exception */export class HTTPException extends Error { readonly res?: Response readonly status: StatusCode
constructor(status: StatusCode = 500, options?: HTTPExceptionOptions) { super(options?.message, { cause: options?.cause }) this.res = options?.res this.status = status }
getResponse(): Response { if (this.res) { return this.res } return new Response(this.message, { status: this.status, }) }}
hono

Version Info

Tagged at
a week ago