Hi,
I'm looping over a list of strings and for each one of them I'm going to make an Alamofire request to an API endpoint.
func readStrings() {
[...]
for name in array {
getResults(artistName: artist)
}
}
func getResults(name: String) {
let headers: HTTPHeaders = [
//request headers
]
let requestEndpoint = "ENDPOINT\(name)"
AF.request(requestEndpoint, headers: headers).validate(statusCode: 200..<300).responseJSON {
[weak self] response in
//Parse the JSON
//If the status code is outside that range, throw an error and break the loop.
}Problem is that when I get an error code, i.e. 409, I'd like my closure to throw, in order for my readStrings() function to break the loop and then display a message to the user.
I don't quite understand well why I can't throw inside that closure. I get this:
Invalid conversion from throwing function of type '(_) throws -> ()' to non-throwing function type '(AFDataResponse<Any>) -> Void' (aka '(DataResponse<Any, AFError>) -> ()')