So, after a little hunting, I found the answer.
Here is my failure:
@Override public void failure(RetrofitError retrofitError) { String serverError = null; try { serverError = extractServerError(retrofitError.getResponse().getBody().in()); } catch (Exception e) { Log.e("LOG_TAG", "Error converting RetrofitError server JSON", e); } if (serverError!=null) { Log.i(LOG_TAG, serverError); } Intent intent = new Intent(ACTION_REGISTRATION_ERROR); intent.putExtra("ServerError", serverError); LocalBroadcastManager.getInstance(FamDooApplication.CONTEXT).sendBroadcastSync(intent); }
And here is the method that is called to retrieve the server error:
public static String extractServerError(java.io.InputStream is) { String serverError = null; String serverErrorDescription = null; try { String s = convertStreamToString(is); JSONObject messageObject = new JSONObject(s); serverError = messageObject.optString("error"); serverErrorDescription = messageObject.optString("error_description"); if (serverErrorDescription!=null && !serverErrorDescription.equals("")) { return serverErrorDescription; } else { return serverError; } //String serverStack = messageObject.getString("stack"); } catch (Exception e) { Log.e("Basemodel", "Error converting RetrofitError server JSON", e); } return ""; }
This will retrieve the error information sent by the service, which is encoded in JSON.
neonDion Dec 16 '13 at 23:20 2013-12-16 23:20
source share