I'm making a request to my server with AlamoFire, and I have a setup something like this, where "self.error" is a String variable.
session.request("https://localhost:3000/my-route", method: .post, parameters: parameters, encoding: JSONEncoding.default).responseJSON { response in
switch response.result {
case .success(let result):
print("nice", result)
case .failure(let err):
self.error = err //self.error is a String state variable
print("failure")
}
}
However, I get the (sensible) error "Cannot assign value of type 'AFError' to type 'String'", because I'm trying to set self.error = err
, and err
is of type AFError, whereas self.error is a String state variable.
I realize I could just do something like self.error = "There was an error", but I'd like to provide the user with some feedback as to what the error actually was, and I can't seem to find the correct properties (i.e. something like err.stringValue, err.description, etc.) to do so. Seems like there's some source code here https://github.com/Alamofire/Alamofire/blob/master/Source/AFError.swift but I'm not sure how this relates to the string value I'd like to obtain.
Any help here would be much appreciated.