I am using RoboSpice to access some rest services I developed using resteasy. I'm returning a JSON object when everything is ok and in the case of an exception I'm returning an http error code and a JSON object describing the nature of the exception. I'm able to get the JSON object when everything is working fine but I'm only able to get the exception and the http error code, but not the JSON I just returned in case of an exception. I have tried doing the same in iOS and I can get everything in every case, anyone knows how to do this using RoboSpice?. By the way I'm using Jackson and Spring. Thanks!
Android: How to get the JSON object returned in case of an exception using RoboSpice
Asked Answered
Take a look at the method explained in this thread for intercepting the http status for a failing request.
Please note that the HttpClientErrorException
has a getResponseBodyAsString()
method that should help you reading the JSON response.
Thanks! This was a REALLY useful tip! Just to add my 2cents, I am using Gson on this returned string, to parse it in a similiar way to how Robospice automatically parses json to POJOs. –
Fording
© 2022 - 2024 — McMap. All rights reserved.
HttpClientErrorException.getResponseBodyAsString()
method – Fumarole