I have a lot of places in the code where Alamofire request/response are handled.
Each of this requests may fail because of some intermittent problem (the most common is flaky network).
I would like to be able to retry requests 3 times before bailing out.
The straightforward method would be to having something like that
var errorCount = 0
func requestType1() {
let request = Alamofire.request(...).responseJSON { response in
if (isError(response) && errorCount < 3) {
errorCount += 1
request1()
}
if (isError(response)) {
handleError()
}
handleSuccess()
}
}
However, I dislike this approach A LOT for multiple reasons. The most obvious is that I will need to implement such code for each request type (and I have something like 15 of them).
I am curios whether there is way to do something like (where the changes are minimal and non intrusive)
let request = Alamofire.request(..., **3**)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…