Android: How to get the JSON object returned in case of an exception using RoboSpice
Asked Answered
F

1

6

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!

Fairlead answered 22/6, 2013 at 19:31 Comment(2)
This might help you: #14864995. Please note the HttpClientErrorException.getResponseBodyAsString()methodFumarole
You're right, rciovati!!! post it as an answer!!! thanks!Fairlead
F
6

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.

Fumarole answered 23/6, 2013 at 19:30 Comment(1)
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.