(error: unknown)
| 77 | * Checks both 'statusCode' (our convention) and 'status' (AI SDK's APICallError convention). |
| 78 | */ |
| 79 | export function getErrorStatusCode(error: unknown): number | undefined { |
| 80 | if (error && typeof error === 'object') { |
| 81 | // Check 'statusCode' first (our convention) |
| 82 | if ('statusCode' in error) { |
| 83 | const statusCode = (error as { statusCode: unknown }).statusCode |
| 84 | if (typeof statusCode === 'number') { |
| 85 | return statusCode |
| 86 | } |
| 87 | } |
| 88 | // Check 'status' (AI SDK's APICallError uses this) |
| 89 | if ('status' in error) { |
| 90 | const status = (error as { status: unknown }).status |
| 91 | if (typeof status === 'number') { |
| 92 | return status |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | return undefined |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Sanitizes error messages for display |
no outgoing calls
no test coverage detected