mirror of
https://github.com/AU-COVIDSafe/mobile-ios.git
synced 2025-04-19 13:05:21 +00:00
COVIDSafe code from version 1.1
This commit is contained in:
commit
3640e52eb2
330 changed files with 261540 additions and 0 deletions
30
CovidSafe/API/CovidRequestRetrier.swift
Normal file
30
CovidSafe/API/CovidRequestRetrier.swift
Normal file
|
@ -0,0 +1,30 @@
|
|||
//
|
||||
// CovidRequestInterceptor.swift
|
||||
// CovidSafe
|
||||
//
|
||||
// Copyright © 2020 Australian Government. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Alamofire
|
||||
final class CovidRequestRetrier: Alamofire.RequestInterceptor {
|
||||
private let numRetries: Int
|
||||
private var retriesExecuted: Int = 0
|
||||
|
||||
init(retries: Int) {
|
||||
self.numRetries = retries
|
||||
}
|
||||
|
||||
func retry(_ request: Request, for session: Session, dueTo error: Error, completion: @escaping (RetryResult) -> Void) {
|
||||
guard let response = request.task?.response as? HTTPURLResponse, response.statusCode == 403 else {
|
||||
/// The request did not fail due to a 403 Forbidden response.
|
||||
let isServerTrustEvaluationError = error.asAFError?.isServerTrustEvaluationError ?? false
|
||||
if ( retriesExecuted >= numRetries || isServerTrustEvaluationError) {
|
||||
return completion(.doNotRetryWithError(error))
|
||||
}
|
||||
retriesExecuted += 1
|
||||
return completion(.retryWithDelay(1.0))
|
||||
}
|
||||
return completion(.doNotRetryWithError(error))
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue