use of com.kickstarter.services.ResponseException in project android-oss by kickstarter.
the class ApiErrorOperator method call.
@Override
public Subscriber<? super Response<T>> call(@NonNull final Subscriber<? super T> subscriber) {
return new Subscriber<retrofit2.Response<T>>() {
@Override
public void onCompleted() {
if (!subscriber.isUnsubscribed()) {
subscriber.onCompleted();
}
}
@Override
public void onError(@NonNull final Throwable e) {
if (!subscriber.isUnsubscribed()) {
subscriber.onError(e);
}
}
@Override
public void onNext(@NonNull final retrofit2.Response<T> response) {
if (subscriber.isUnsubscribed()) {
return;
}
if (!response.isSuccess()) {
try {
final ErrorEnvelope envelope = gson.fromJson(response.errorBody().string(), ErrorEnvelope.class);
subscriber.onError(new ApiException(envelope, response));
} catch (@NonNull final IOException e) {
subscriber.onError(new ResponseException(response));
}
}
subscriber.onNext(response.body());
}
};
}
Aggregations