{"version":3,"sources":["../src/server/http-exception.ts"],"names":[],"mappings":";;;AA0GO,IAAM,aAAA,GAAN,cAA4B,KAAA,CAAM;AAAA,EAC9B,GAAA;AAAA,EACA,MAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOT,WAAA,CAAY,MAAA,GAAqB,GAAA,EAAK,OAAA,EAAgC;AACpE,IAAA,KAAA,CAAM,SAAS,OAAA,EAAS,EAAE,KAAA,EAAO,OAAA,EAAS,OAAO,CAAA;AACjD,IAAA,IAAA,CAAK,MAAM,OAAA,EAAS,GAAA;AACpB,IAAA,IAAA,CAAK,MAAA,GAAS,MAAA;AACd,IAAA,IAAA,CAAK,KAAA,GAAQ,OAAA,EAAS,KAAA,IAAS,IAAA,CAAK,KAAA;AAAA,EACtC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,WAAA,GAAwB;AACtB,IAAA,IAAI,KAAK,GAAA,EAAK;AACZ,MAAA,MAAM,WAAA,GAAc,IAAI,QAAA,CAAS,IAAA,CAAK,IAAI,IAAA,EAAM;AAAA,QAC9C,QAAQ,IAAA,CAAK,MAAA;AAAA,QACb,OAAA,EAAS,KAAK,GAAA,CAAI;AAAA,OACnB,CAAA;AACD,MAAA,OAAO,WAAA;AAAA,IACT;AACA,IAAA,OAAO,IAAI,QAAA,CAAS,IAAA,CAAK,OAAA,EAAS;AAAA,MAChC,QAAQ,IAAA,CAAK;AAAA,KACd,CAAA;AAAA,EACH;AACF","file":"chunk-64ITUOXI.cjs","sourcesContent":["// Copied from https://github.com/honojs/hono/blob/main/packages/hono/src/http-exception.ts\n\n/**\n * @module\n * This module provides the `HTTPException` class.\n */\n\ntype InfoStatusCode = 100 | 101 | 102 | 103;\ntype SuccessStatusCode = 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 226;\ntype DeprecatedStatusCode = 305 | 306;\ntype RedirectStatusCode = 300 | 301 | 302 | 303 | 304 | DeprecatedStatusCode | 307 | 308;\ntype ClientErrorStatusCode =\n | 400\n | 401\n | 402\n | 403\n | 404\n | 405\n | 406\n | 407\n | 408\n | 409\n | 410\n | 411\n | 412\n | 413\n | 414\n | 415\n | 416\n | 417\n | 418\n | 421\n | 422\n | 423\n | 424\n | 425\n | 426\n | 428\n | 429\n | 431\n | 451;\ntype ServerErrorStatusCode = 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511;\n\n/**\n * `UnofficialStatusCode` can be used to specify an unofficial status code.\n * @example\n *\n * ```ts\n * app.get('/unknown', (c) => {\n * return c.text(\"Unknown Error\", 520 as UnofficialStatusCode)\n * })\n * ```\n */\nexport type UnofficialStatusCode = -1;\n\n/**\n * If you want to use an unofficial status, use `UnofficialStatusCode`.\n */\nexport type StatusCode =\n | InfoStatusCode\n | SuccessStatusCode\n | RedirectStatusCode\n | ClientErrorStatusCode\n | ServerErrorStatusCode\n | UnofficialStatusCode;\n\n/**\n * Options for creating an `HTTPException`.\n * @property res - Optional response object to use.\n * @property message - Optional custom error message.\n * @property cause - Optional cause of the error.\n * @property stack - Optional stack trace for the error.\n */\ntype HTTPExceptionOptions = {\n res?: Response;\n message?: string;\n cause?: unknown;\n stack?: string;\n};\n\n/**\n * `HTTPException` must be used when a fatal error such as authentication failure occurs.\n *\n * @see {@link https://hono.dev/docs/api/exception}\n *\n * @param {StatusCode} status - status code of HTTPException\n * @param {HTTPExceptionOptions} options - options of HTTPException\n * @param {HTTPExceptionOptions[\"res\"]} options.res - response of options of HTTPException\n * @param {HTTPExceptionOptions[\"message\"]} options.message - message of options of HTTPException\n * @param {HTTPExceptionOptions[\"cause\"]} options.cause - cause of options of HTTPException\n *\n * @example\n * ```ts\n * import { HTTPException } from 'hono/http-exception'\n *\n * // ...\n *\n * app.post('/auth', async (c, next) => {\n * // authentication\n * if (authorized === false) {\n * throw new HTTPException(401, { message: 'Custom error message' })\n * }\n * await next()\n * })\n * ```\n */\nexport class HTTPException extends Error {\n readonly res?: Response;\n readonly status: StatusCode;\n\n /**\n * Creates an instance of `HTTPException`.\n * @param status - HTTP status code for the exception. Defaults to 500.\n * @param options - Additional options for the exception.\n */\n constructor(status: StatusCode = 500, options?: HTTPExceptionOptions) {\n super(options?.message, { cause: options?.cause });\n this.res = options?.res;\n this.status = status;\n this.stack = options?.stack || this.stack;\n }\n\n /**\n * Returns the response object associated with the exception.\n * If a response object is not provided, a new response is created with the error message and status code.\n * @returns The response object.\n */\n getResponse(): Response {\n if (this.res) {\n const newResponse = new Response(this.res.body, {\n status: this.status,\n headers: this.res.headers,\n });\n return newResponse;\n }\n return new Response(this.message, {\n status: this.status,\n });\n }\n}\n"]}