I am using the Retrofit library to do REST calls to a service I am using.
If I make an API call to my service and have a failure, the service returns a bit of JSON
getBodyAs
to get a JSON Object.JsonObject responseAsJson = (JsonObject) retrofitError.getBodyAs(JsonElement.class);
String message = responseAsJson.get("error").getAsString(); //=> "Username already in use"
Confirmed working in Retrofit 1.x. Not sure what changes are required for Retrofit 2.x.