* Extracts the error message from various error structures
(error: unknown)
| 50 | * Extracts the error message from various error structures |
| 51 | */ |
| 52 | function extractErrorMessage(error: unknown): string { |
| 53 | if (error instanceof Error) { |
| 54 | return error.message; |
| 55 | } |
| 56 | |
| 57 | // API error response structures |
| 58 | const apiError = (error as any)?.response?.data?.error; |
| 59 | if (apiError) { |
| 60 | if (typeof apiError === 'string') { |
| 61 | return apiError; |
| 62 | } |
| 63 | if (apiError.message) { |
| 64 | return apiError.message; |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | // Direct error data |
| 69 | const errorData = (error as any)?.error; |
| 70 | if (errorData) { |
| 71 | if (typeof errorData === 'string') { |
| 72 | return errorData; |
| 73 | } |
| 74 | if (errorData.message) { |
| 75 | return errorData.message; |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | // Fallback |
| 80 | if (typeof error === 'string') { |
| 81 | return error; |
| 82 | } |
| 83 | |
| 84 | return 'An unknown error occurred'; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Checks if the error message indicates a model not found error |
no outgoing calls
no test coverage detected
searching dependent graphs…