* Determines if an error is retryable based on the error type and status code
(error: any)
| 115 | * Determines if an error is retryable based on the error type and status code |
| 116 | */ |
| 117 | function isRetryableError(error: any): boolean { |
| 118 | // Context length errors are never retryable - they need user intervention |
| 119 | if (isContextLengthError(error)) { |
| 120 | return false; |
| 121 | } |
| 122 | |
| 123 | // Network errors are retryable |
| 124 | if (isNetworkError(error)) { |
| 125 | return true; |
| 126 | } |
| 127 | |
| 128 | // HTTP status codes that are retryable |
| 129 | if (error.status && isRetryableHttpStatus(error.status)) { |
| 130 | return true; |
| 131 | } |
| 132 | |
| 133 | // OpenAI/API specific errors |
| 134 | if (isServerError(error)) { |
| 135 | return true; |
| 136 | } |
| 137 | |
| 138 | // Check for connection issues by message content |
| 139 | const errorMessage = error.message?.toLowerCase(); |
| 140 | if (errorMessage && isConnectionError(errorMessage)) { |
| 141 | return true; |
| 142 | } |
| 143 | |
| 144 | return false; |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * Calculates the delay for the next retry attempt |
no test coverage detected