(error: unknown, fallback: string)
| 14 | |
| 15 | // Normalize unknown errors to a user-facing string. |
| 16 | const extractErrorMessage = (error: unknown, fallback: string): string => { |
| 17 | if (typeof error === 'string') { |
| 18 | return error |
| 19 | } |
| 20 | if (error instanceof Error && error.message) { |
| 21 | return error.message + (error.stack ? `\n\n${error.stack}` : '') |
| 22 | } |
| 23 | if (error && typeof error === 'object' && 'message' in error) { |
| 24 | const candidate = (error as { message: unknown }).message |
| 25 | if (typeof candidate === 'string' && candidate.length > 0) { |
| 26 | return candidate |
| 27 | } |
| 28 | } |
| 29 | return fallback |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Check if an error indicates the user is out of credits. |
no outgoing calls
no test coverage detected