* Converts errors to strongly-typed SendMessageError
(error: unknown)
| 3423 | * Converts errors to strongly-typed SendMessageError |
| 3424 | */ |
| 3425 | private convertToSendMessageError(error: unknown): SendMessageError { |
| 3426 | // Check for specific AI SDK errors using type guards |
| 3427 | if (LoadAPIKeyError.isInstance(error)) { |
| 3428 | return { |
| 3429 | type: "api_key_not_found", |
| 3430 | provider: "anthropic", // We can infer this from LoadAPIKeyError context |
| 3431 | }; |
| 3432 | } |
| 3433 | |
| 3434 | // TODO: Add more specific error types as needed |
| 3435 | // if (APICallError.isInstance(error)) { |
| 3436 | // if (error.statusCode === 401) return { type: "authentication", ... }; |
| 3437 | // if (error.statusCode === 429) return { type: "rate_limit", ... }; |
| 3438 | // } |
| 3439 | // if (RetryError.isInstance(error)) { |
| 3440 | // return { type: "retry_failed", ... }; |
| 3441 | // } |
| 3442 | |
| 3443 | // Fallback for unknown errors |
| 3444 | const message = getErrorMessage(error); |
| 3445 | return { type: "unknown", raw: message }; |
| 3446 | } |
| 3447 | |
| 3448 | /** |
| 3449 | * Categorizes errors for better error handling (used for event emission) |
no test coverage detected