(error: unknown)
| 5 | * Handles Error objects, strings, and unknown error types. |
| 6 | */ |
| 7 | export function getErrorMessage(error: unknown): string { |
| 8 | if (error instanceof Error) { |
| 9 | return error.message; |
| 10 | } |
| 11 | if (typeof error === 'string') { |
| 12 | return error; |
| 13 | } |
| 14 | if (error && typeof error === 'object' && 'message' in error) { |
| 15 | return String((error as { message: unknown }).message); |
| 16 | } |
| 17 | return 'An unexpected error occurred'; |
| 18 | } |
| 19 | |
| 20 | /** |
| 21 | * Type guard to check if an error is an AbortError (e.g., from cancelled operations) |
no outgoing calls
no test coverage detected