some immediate thoughts/notes:
as(BITLY_USER, BITLY_API_KEY).call(shorten(urlToBeShortened)).getShortUrl()
is something that you control.Observable.create
is pretty verbose and is used more in cases where you're trying to create an observable that does something fancy vs executing a chain of existing operators. .just
or .from
are better starting observables in cases where the initial emission is instant.Here's a scratchpad version (i haven't tested or even checked this for syntax, so YMMV):
```
Observable.just(urlToBeShortened) .flatMap(new Func1<String, Observable<String>>() { @Override public Observable<String> call(String bitlyUrl) { // I'm guessing this is an async task? return as(BITLY_USER, BITLY_API_KEY).call(shorten(urlToBeShortened)).getShortUrl(); } }) .onErrorResumeNext(new Func1<Throwable, Observable<? extends String>>() { @Override public Observable<? extends String> call(Throwable throwable) { Log.i("onErrorResumeNext", "message " + throwable.getMessage()); if (throwable instanceof BitlyTask.AlreadyABitLyLinkException) { return Observable.just(((BitlyTask.AlreadyABitLyLinkException) throwable).getSourceUrl()); } else { return Observable.empty(); } } }); ```