func shouldRetryRequest()

in AWSAppSyncClient/Internal/AWSAppSyncRetryHandler.swift [64:108]


    func shouldRetryRequest(for error: AWSAppSyncClientError) -> AWSAppSyncRetryAdvice {
        currentAttemptNumber += 1

        var httpResponse: HTTPURLResponse?

        switch error {
        case .requestFailed(_, let reponse, _):
            httpResponse = reponse
        case .noData(let response):
            httpResponse = response
        case .parseError(_, let response, _):
            httpResponse = response
        case .authenticationError:
            httpResponse = nil
        }
        
        /// If no known error and we did not receive an HTTP response, we return false.
        guard let unwrappedResponse = httpResponse  else {
            return AWSAppSyncRetryAdvice(shouldRetry: false, retryInterval: nil)
        }
        
        if let retryAfterValueInSeconds = AWSAppSyncRetryHandler.getRetryAfterHeaderValue(from: unwrappedResponse) {
            return AWSAppSyncRetryAdvice(shouldRetry: true, retryInterval: .seconds(retryAfterValueInSeconds))
        }
        
        // If using aggressive retry strategy, we attempt a maximum 12 times.
        if self.retryStrategy == .aggressive &&
            currentAttemptNumber > AWSAppSyncRetryHandler.maxRetryAttemptsWhenUsingAggresiveMode {
            return AWSAppSyncRetryAdvice(shouldRetry: false, retryInterval: nil)
        }
        
        let waitMillis = AWSAppSyncRetryHandler.retryDelayInMillseconds(for: currentAttemptNumber, retryStrategy: retryStrategy)

        switch unwrappedResponse.statusCode {
        case 500 ... 599, 429:
            if waitMillis > AWSAppSyncRetryHandler.maxWaitMilliseconds {
                break
            } else {
                return AWSAppSyncRetryAdvice(shouldRetry: true, retryInterval: .milliseconds(waitMillis))
            }
        default:
            break
        }
        return AWSAppSyncRetryAdvice(shouldRetry: false, retryInterval: nil)
    }