Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save shishirthedev/70eb23aa294c34ad72d9b164a09aefcb to your computer and use it in GitHub Desktop.

Select an option

Save shishirthedev/70eb23aa294c34ad72d9b164a09aefcb to your computer and use it in GitHub Desktop.
// Way 1
public void onError(Throwable e){
Gson gson = new Gson();
TypeAdapter<YourResponseModel> adapter = gson.getAdapter(YourResponseModel.class);
try {
if (response.errorBody() != null)
registerResponse =
adapter.fromJson(
response.errorBody().string());
} catch (IOException e) {
e.printStackTrace();
}
}
// Way 2
public void onError(Throwable e) {
if (e instanceof HttpException) {
HttpException exception = (HttpException) e;
Response response = exception.response();
try {
JSONObject jsonObject = new JSONObjec(response.errorBody().string());
Log.e("Error ","" + jsonObject.optString("message"));
} catch (JSONException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment