| 93 | * Falls back to the generic {@link OpenWAApiError} for unmapped statuses. |
| 94 | */ |
| 95 | export function classifyApiError(status: number, message: string, body: unknown, errorKind?: string): OpenWAApiError { |
| 96 | switch (status) { |
| 97 | case 401: |
| 98 | return new OpenWAAuthError(message, status, body, errorKind); |
| 99 | case 403: |
| 100 | return new OpenWAForbiddenError(message, status, body, errorKind); |
| 101 | case 404: |
| 102 | return new OpenWANotFoundError(message, status, body, errorKind); |
| 103 | case 409: |
| 104 | return new OpenWAConflictError(message, status, body, errorKind); |
| 105 | case 429: |
| 106 | return new OpenWARateLimitError(message, status, body, errorKind); |
| 107 | case 501: |
| 108 | return new OpenWANotImplementedError(message, status, body, errorKind); |
| 109 | default: |
| 110 | return new OpenWAApiError(message, status, body, errorKind); |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | /** Narrow the NestJS error envelope shape: `{ statusCode, message, error }`. */ |
| 115 | interface NestErrorEnvelope { |