* Check if an error is an OAuth authentication error (expired/invalid token). * This indicates we should try refreshing the token.
(error: unknown)
| 170 | * This indicates we should try refreshing the token. |
| 171 | */ |
| 172 | function isOAuthAuthError(error: unknown): boolean { |
| 173 | if (!error || typeof error !== 'object') return false |
| 174 | |
| 175 | // Check status code (handles both 'status' from AI SDK and 'statusCode' from our errors) |
| 176 | const statusCode = getErrorStatusCode(error) |
| 177 | if (statusCode === 401 || statusCode === 403) return true |
| 178 | |
| 179 | // Check error message for auth indicators |
| 180 | const err = error as { |
| 181 | message?: string |
| 182 | responseBody?: string |
| 183 | } |
| 184 | const message = (err.message || '').toLowerCase() |
| 185 | const responseBody = (err.responseBody || '').toLowerCase() |
| 186 | |
| 187 | if (message.includes('unauthorized') || message.includes('invalid_token')) |
| 188 | return true |
| 189 | if (message.includes('authentication') || message.includes('expired')) |
| 190 | return true |
| 191 | if ( |
| 192 | responseBody.includes('unauthorized') || |
| 193 | responseBody.includes('invalid_token') |
| 194 | ) |
| 195 | return true |
| 196 | if ( |
| 197 | responseBody.includes('authentication') || |
| 198 | responseBody.includes('expired') |
| 199 | ) |
| 200 | return true |
| 201 | |
| 202 | return false |
| 203 | } |
| 204 | |
| 205 | function getModelProvider(model: LanguageModel): string { |
| 206 | if (typeof model === 'string') return model |
no test coverage detected