(error: unknown)
| 45 | * Default retry condition for rate limiting errors |
| 46 | */ |
| 47 | export function isRetryableError(error: unknown): boolean { |
| 48 | if (!isRetryableErrorType(error)) return false |
| 49 | |
| 50 | // Check for rate limiting status codes |
| 51 | if ( |
| 52 | hasStatus(error) && |
| 53 | (error.status === 429 || error.status === 502 || error.status === 503 || error.status === 504) |
| 54 | ) { |
| 55 | return true |
| 56 | } |
| 57 | |
| 58 | // Check for network-level errors (DNS, connection, timeout) |
| 59 | const errorMessage = toError(error).message |
| 60 | const lowerMessage = errorMessage.toLowerCase() |
| 61 | |
| 62 | const networkKeywords = [ |
| 63 | 'fetch failed', |
| 64 | 'econnreset', |
| 65 | 'econnrefused', |
| 66 | 'etimedout', |
| 67 | 'enetunreach', |
| 68 | 'socket hang up', |
| 69 | 'network error', |
| 70 | // Transient DNS resolution failure surfaced by secureFetchWithValidation |
| 71 | // before the request is made. The deterministic "resolves to a blocked IP |
| 72 | // address" security rejection is a distinct message and stays non-retryable. |
| 73 | 'could not be resolved', |
| 74 | ] |
| 75 | |
| 76 | if (networkKeywords.some((keyword) => lowerMessage.includes(keyword))) { |
| 77 | return true |
| 78 | } |
| 79 | |
| 80 | // Check for rate limiting in error messages |
| 81 | const rateLimitKeywords = [ |
| 82 | 'rate limit', |
| 83 | 'rate_limit', |
| 84 | 'too many requests', |
| 85 | 'quota exceeded', |
| 86 | 'throttled', |
| 87 | 'retry after', |
| 88 | 'temporarily unavailable', |
| 89 | 'service unavailable', |
| 90 | ] |
| 91 | |
| 92 | return rateLimitKeywords.some((keyword) => lowerMessage.includes(keyword)) |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Executes a function with exponential backoff retry logic |
no test coverage detected