Last active
January 24, 2019 04:47
-
-
Save shishirthedev/70eb23aa294c34ad72d9b164a09aefcb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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