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

Function isOAuthRateLimitError

sdk/src/impl/llm.ts:142–166  ·  view source on GitHub ↗

* Check if an error is an OAuth rate limit error that should trigger fallback.

(error: unknown)

Source from the content-addressed store, hash-verified

140 * Check if an error is an OAuth rate limit error that should trigger fallback.
141 */
142function 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).

Callers 1

Calls 1

getErrorStatusCodeFunction · 0.90

Tested by

no test coverage detected