fix(core): improve API response error handling and retry logic (#14563)

This commit is contained in:
matt korwel
2025-12-05 09:49:08 -08:00
committed by GitHub
parent 738354ff65
commit dd3fd73ffe
8 changed files with 375 additions and 45 deletions
+9 -8
View File
@@ -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,
};