RxJavaErrorHandlingCallAdapterFactory create() {
return new RxJavaErrorHandlingCallAdapterFactory();
}
private final CallAdapter.Factory original = RxJavaCallAdapterFactory.create();
@Override
public CallAdapter<?, ?> get(Type returnType, Annotation[] annotations, Retrofit retrofit) {
return new RxJavaCallAdapterWrapper(original.get(returnType, annotations, retrofit));
}
private static class RxJavaCallAdapterWrapper<R>
implements CallAdapter<R, Observable<?>> {
private final CallAdapter<R, ?> original;
public RxJavaCallAdapterWrapper(CallAdapter<R, ?> original) {
this.original = original;
}
@Override
public Type responseType() {
return original.responseType();
}
@Override
public Observable<?> adapt(Call<R> call) {
return ((Observable<?>) original.adapt(call))
.onErrorResumeNext(new ErrorHandler<>());
}
}
}