Skip to content

Instantly share code, notes, and snippets.

@parthdave93
Last active March 1, 2017 05:44
Show Gist options
  • Save parthdave93/559f2f99ff4b2bceed4213e4e926da5f to your computer and use it in GitHub Desktop.
Save parthdave93/559f2f99ff4b2bceed4213e4e926da5f to your computer and use it in GitHub Desktop.
Retrofit will throw error for 401,402 type server response if we want to catch that in RxJava, Things to do for Retrofit RxJava Error Handling -> Check OperatorMapResponseToBodyOrError.java for error handling other classes are just to instanciate the Rxjava adapter on proejct level
if (throwable instanceof HttpException) {
Response response = ((HttpException) throwable).response();
RetrofitError commonResponse = null;
if (response != null) {
Gson gson = new Gson();
try {
commonResponse = gson.fromJson(response.errorBody().string(), RetrofitError.class);
CommonUtilities.showAlertDialog(context, commonResponse.getMessage());
} catch (IOException e) {
e.printStackTrace();
}
}
webApiResponseInterface.onError(commonResponse);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment