Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapping onError notifications #3652

Closed
twz123 opened this issue Jan 27, 2016 · 6 comments
Closed

Mapping onError notifications #3652

twz123 opened this issue Jan 27, 2016 · 6 comments
Labels

Comments

@twz123
Copy link

twz123 commented Jan 27, 2016

I often have the use case that I want to map the Throwable emitted by an onError notification of an Observable to something else, for example wrapping or unwrapping it.

Maybe I missed something, but apparently there is no stock solution in RxJava to achieve this. Currently, I use a custom Operator. Would it make sense to add such an Operator along with its corresponding Observable.mapError / Single.mapError methods to RxJava directly?

@akarnokd
Copy link
Member

There is the onErrorReturn and onErrorResumeNext operators that will give you the Throwable which you can then map to a value or another error through Observable.error(), i.e.:

source.onErrorResumeNext(e -> Observable.error(e.getCause()))...

@davidmoten
Copy link
Collaborator

'materialize()' is useful in this regard too

On Wed, 27 Jan 2016 19:56 David Karnok [email protected] wrote:

There is the onErrorReturn and onErrorResumeNext operators that will give
you the Throwable which you can then map to a value or another error
through Observable.error(), i.e.:

source.onErrorResumeNext(e -> Observable.error(e.getCause()))...


Reply to this email directly or view it on GitHub
#3652 (comment).

@twz123
Copy link
Author

twz123 commented Jan 28, 2016

Ah yeah, onErrorResumeNext is a bit more verbose, but does the trick, thanks! On the other hand, there's no onErrorResumeNext for Single, only onErrorReturn, which cannot be used for the described use case.

Would it then perhaps make sense to add an implementation of onErrorResumeNext to Single, too?

@artem-zinnatullin
Copy link
Contributor

I'll add required operators for Single, first one is #3655, next one later.

@twz123 looks like your issue is now resolved? If so — please close it :)

@twz123
Copy link
Author

twz123 commented Jan 29, 2016

Cool! onErrorResumeNext(Func1<Throwable, Single>) would be the thing I need. I'll close this and wait for the PR ;) Thanks a lot!

@twz123
Copy link
Author

twz123 commented Mar 15, 2016

See #3766 for second part...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants