Skip to content

Instantly share code, notes, and snippets.

@gibson-khs
Last active November 28, 2017 08:29
Show Gist options
  • Select an option

  • Save gibson-khs/b051a3083a9f1cf501b5946d782d562a to your computer and use it in GitHub Desktop.

Select an option

Save gibson-khs/b051a3083a9f1cf501b5946d782d562a to your computer and use it in GitHub Desktop.
if (throwable instanceof HttpException) {
HttpException exception = (HttpException) throwable;
RestError restError = (RestError) retrofit.responseBodyConverter(
RestError.class, RestError.class.getAnnotations()).convert(exception.response().errorBody());
String errorMessage = restError.message;
if (!TextUtils.isEmpty(errorMessage)) {
Toast.makeText(context, errorMessage, Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(context, context.getResources().getString(R.string.default_error), Toast.LENGTH_LONG).show();
}
}
public class RestError {
@SerializedName("error_message")
public String message;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment