← full-stack-fastapi-template / frontend/src/client/core/ApiError.ts
| 1 | import type { ApiRequestOptions } from './ApiRequestOptions'; |
| 2 | import type { ApiResult } from './ApiResult'; |
| 3 | |
| 4 | export class ApiError extends Error { |
| 5 | public readonly url: string; |
| 6 | public readonly status: number; |
| 7 | public readonly statusText: string; |
| 8 | public readonly body: unknown; |
| 9 | public readonly request: ApiRequestOptions; |
| 10 | |
| 11 | constructor(request: ApiRequestOptions, response: ApiResult, message: string) { |
| 12 | super(message); |
| 13 | |
| 14 | this.name = 'ApiError'; |
| 15 | this.url = response.url; |
| 16 | this.status = response.status; |
| 17 | this.statusText = response.statusText; |
| 18 | this.body = response.body; |
| 19 | this.request = request; |
| 20 | } |
| 21 | } |