-
-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to get json returned when server response is 422 ? #53
Comments
Hi @ntkon Glad you like it ! :) In case of and error you should be able to get the json via the import ws
[...]
myApiCall().onError { e in
if let wsError = e as? WSError {
print(wsError.code)
print(wsError.status)
print(wsError.jsonPayload)
}
} While we're at it a very common use case is to bridge the default public func edit(_ user: YPUser) -> AsyncTask {
return ws.put(restURL(user), params: paramsDicForUser(user)).bridgeError { error in
if let e = error as? WSError, e.status == .forbidden {
throw YPError.forbidden
}
}
} This enables you to have only your own domain error inside the app and removes the need to import ws in your ViewControllers :) Hope this helps, |
Thanks for that @s4cha , I'm still to figure out how to use errors properly, but will get to it (any tips/sample would be welcome). Sometimes the jsonPayload is not present, specially when there are errors. It seems that if I get anything wrong in the api call, I end up with the cryptic -1-Unknown error. I need to figure out how to handle it when my api call is off, so that I can at least get something useful to track down. Thanks again for your prompt reply, it's much appreciated. |
Hi @s4cha , Is there a way that I can just get the returned data (which in this case is not json) and then do my own analysis? Or does alamofire drop this data before ws gets a look in? I tried to use the bridgeError, but it was being called with a WSError, which only 'status' = 'unknown' and 'jsonPayload' = nil Thanks. |
Hi,
I'm calling a rest api and the server is returning server response 422, but the error I'm getting in the onError block shows 'unknown' with message '-1 - Unknown'
The log shows:
When I run the api in swagger the json returned is:
and the headers shown are:
Thanks,
WS is great and thanks for all your efforts.
The text was updated successfully, but these errors were encountered: