mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-22 02:54:31 -07:00
fix(core): improve API response error handling and retry logic (#14563)
This commit is contained in:
@@ -35,7 +35,7 @@ const DEFAULT_RETRY_OPTIONS: RetryOptions = {
|
||||
maxAttempts: 3,
|
||||
initialDelayMs: 5000,
|
||||
maxDelayMs: 30000, // 30 seconds
|
||||
shouldRetryOnError: defaultShouldRetry,
|
||||
shouldRetryOnError: isRetryableError,
|
||||
};
|
||||
|
||||
const RETRYABLE_NETWORK_CODES = [
|
||||
@@ -79,21 +79,21 @@ const FETCH_FAILED_MESSAGE = 'fetch failed';
|
||||
* @param retryFetchErrors Whether to retry on specific fetch errors.
|
||||
* @returns True if the error is a transient error, false otherwise.
|
||||
*/
|
||||
function defaultShouldRetry(
|
||||
export function isRetryableError(
|
||||
error: Error | unknown,
|
||||
retryFetchErrors?: boolean,
|
||||
): boolean {
|
||||
// Check for common network error codes
|
||||
const errorCode = getNetworkErrorCode(error);
|
||||
if (errorCode && RETRYABLE_NETWORK_CODES.includes(errorCode)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (retryFetchErrors && error instanceof Error) {
|
||||
// Check for generic fetch failed message (case-insensitive)
|
||||
if (error.message.toLowerCase().includes(FETCH_FAILED_MESSAGE)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check for common network error codes
|
||||
const errorCode = getNetworkErrorCode(error);
|
||||
if (errorCode && RETRYABLE_NETWORK_CODES.includes(errorCode)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Priority check for ApiError
|
||||
@@ -147,6 +147,7 @@ export async function retryWithBackoff<T>(
|
||||
signal,
|
||||
} = {
|
||||
...DEFAULT_RETRY_OPTIONS,
|
||||
shouldRetryOnError: isRetryableError,
|
||||
...cleanOptions,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user