File
Blob: src/shared/web/http.ts
| 1 | /** |
| 2 | * HTTP error class for consistent status propagation in UI routes. |
| 3 | */ |
| 4 | export class HttpError extends Error { |
| 5 | status: number; |
| 6 | expose: boolean; |
| 7 | constructor(status: number, message: string, options?: { expose?: boolean; cause?: unknown }) { |
| 8 | super(message); |
| 9 | this.name = "HttpError"; |
| 10 | this.status = status; |
| 11 | this.expose = Boolean(options?.expose); |
| 12 | if (options?.cause) { |
| 13 | // @ts-ignore |
| 14 | this.cause = options.cause; |
| 15 | } |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | export function isHttpError(e: unknown): e is HttpError { |
| 20 | return ( |
| 21 | e instanceof Error && (e as any).name === "HttpError" && typeof (e as any).status === "number" |
| 22 | ); |
| 23 | } |