* Check if an error is an OAuth rate limit error that should trigger fallback.
(error: unknown)
| 140 | * Check if an error is an OAuth rate limit error that should trigger fallback. |
| 141 | */ |
| 142 | function isOAuthRateLimitError(error: unknown): boolean { |
| 143 | if (!error || typeof error !== 'object') return false |
| 144 | |
| 145 | // Check status code (handles both 'status' from AI SDK and 'statusCode' from our errors) |
| 146 | const statusCode = getErrorStatusCode(error) |
| 147 | if (statusCode === 429) return true |
| 148 | |
| 149 | // Check error message for rate limit indicators |
| 150 | const err = error as { |
| 151 | message?: string |
| 152 | responseBody?: string |
| 153 | } |
| 154 | const message = (err.message || '').toLowerCase() |
| 155 | const responseBody = (err.responseBody || '').toLowerCase() |
| 156 | |
| 157 | if (message.includes('rate_limit') || message.includes('rate limit')) |
| 158 | return true |
| 159 | if ( |
| 160 | responseBody.includes('rate_limit') || |
| 161 | responseBody.includes('rate limit') |
| 162 | ) |
| 163 | return true |
| 164 | |
| 165 | return false |
| 166 | } |
| 167 | |
| 168 | /** |
| 169 | * Check if an error is an OAuth authentication error (expired/invalid token). |
no test coverage detected