I am trying to do an API request to the backend using alamofire and responseDecodable.
AF.request(Router.registerFacebookUser(facebookToken: token)).validate().responseDecodable(of: UserConfig.self) { result in
switch result.result {
case let .success(userConfig):
onAuthentication(userConfig)
case let .failure(error):
print(error)
//somehow get the message from ERROR JSON and pass it here
onFailure(error.localizedDescription)
}
}
When call succeeds, it successfully parses JSON to the model. However, there as some special cases, when it should fail. For example if user is already registered, I get a response JSON:
{
"error":{
"message":"User already exist"
}
}
Is it possible to override the AF error that we receive? Or maybe it's possible to parse another object if request fails? Or are there other ways how I can access the error message?