AlamofireObjectMapper
AlamofireObjectMapper copied to clipboard
How do I print error json from responseObject ?
Alamofire.request(URL, method: Endpoints.login.method, parameters: parameters, encoding: JSONEncoding.default, headers: nil)
.validate()
.responseObject { [weak self] (response: DataResponse<User>) in
switch response.result {
case .success(let user):
cb(.success(user))
case .failure(let error):
log.error(error)
cb(.failure(error))
}
}
If I enter wrong password then I am unable to print the exact error message which api is sending it to me.
po error.localizedDescription
I am always getting default message from alamofire i.e. "Response status code was unacceptable: 401.
". It should print the dynamic error message like Invalid username and password
.
Btw I can use responseJson to print the dynamic error message using
.responseJSON { response in
if response.response?.statusCode == 200 {
print("Success with JSON: \(response.result.value)")
}
else {
let error = response.result.value as! NSDictionary
let errorMessage = error.object(forKey: "message") as! String
print(errorMessage)
}
But how I should do the same with responseObject
?
Did you got solution for responseObject? while I am also facing same issue now.
Me too !