MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / isOAuthAuthError

Function isOAuthAuthError

sdk/src/impl/llm.ts:172–203  ·  view source on GitHub ↗

* Check if an error is an OAuth authentication error (expired/invalid token). * This indicates we should try refreshing the token.

(error: unknown)

Source from the content-addressed store, hash-verified

170 * This indicates we should try refreshing the token.
171 */
172function 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
205function getModelProvider(model: LanguageModel): string {
206 if (typeof model === 'string') return model

Callers 1

Calls 1

getErrorStatusCodeFunction · 0.90

Tested by

no test coverage detected