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

Feature request: add onErrorResumeNext #1665

Closed
danhyun opened this issue Apr 28, 2016 · 8 comments
Closed

Feature request: add onErrorResumeNext #1665

danhyun opened this issue Apr 28, 2016 · 8 comments
Labels
help wanted Issues we wouldn't mind assistance with.

Comments

@danhyun
Copy link

danhyun commented Apr 28, 2016

According to https://github.com/ReactiveX/rxjs/blob/master/MIGRATION.md we're to file an issue or PR requesting feature additions to RxJS5.

I'd like to have something like onErrorResumeNext http://xgrommx.github.io/rx-book/content/observable/observable_methods/onerrorresumenext.html or the ability to continue with the next emitted item.

In my specific usecase I'm doing something like this:

Rx.Observable.from([1, 2, 3, 4])
  .map(i => {
    if (i == 2) {
       throw new Error('no 2s');
    }
    return i;
  })
  //.onErrorResumeNext(somefunc) // short circuit to subscriber's on error
  .do(i => console.log('map 1: ' + i))
  .map(i => i + 1)
  //.onErrorResumeNext(somefunc) // short circuit to subscriber's on error
  .do(i => console.log('map 2: ' + i))
  .map(i => {
    if (i & 0 == 0) {
      throw new Error('no evens');
    }
    return i * 2;
  })
  .do(i => console.log('map 3: ' + i))
//.onErrorResumeNext(somefunc) // short circuit to subscriber's on error
  .subscribe(
    i => console.log('found ' + i),
    e => console.log('error ' + e),
    () => console.log('done')
  );

Related JSBin http://jsbin.com/monuyegatu/1/edit?html,js,console

@trxcllnt
Copy link
Member

Have you seen catch (and tests)?

@danhyun
Copy link
Author

danhyun commented Apr 29, 2016

Thanks @trxcllnt those are awesome resources.

I'm still having a bit of trouble here, so in my use case I'm creating a cold observable from an array. Trying to use catch it looks like it replaces the rest of the sequence rather than replacing just that single item. Given that, is there any way to get the remaining sequence from catch?

  .catch((e, o) => {
    console.log('Handling error: ' + e);
    return Rx.Observable.from([1,2,3,4]); // any way to recover and resume the existing cold observable sequence?
  })

Since my Observable has a number of transformations I'd like to shortciruit the processing of this current item and just proceed to the next one. I haven't been able to tease out how I would do this right now without keeping track of the items I've processed or without something like Observable#onErrorResumeNext()

@benlesh
Copy link
Member

benlesh commented Apr 29, 2016

Yeah, we need to add onErrorResumeNext

@benlesh benlesh changed the title RxJS5 feature request: Ability to continue emitting items in face of error Feature request: add onErrorResumeNext Apr 29, 2016
@benlesh benlesh added the help wanted Issues we wouldn't mind assistance with. label Apr 29, 2016
kwonoj added a commit to kwonoj/rxjs that referenced this issue May 3, 2016
kwonoj added a commit to kwonoj/rxjs that referenced this issue May 3, 2016
@benlesh benlesh closed this as completed in 51e022b May 4, 2016
@danhyun
Copy link
Author

danhyun commented May 4, 2016

Thanks!

@omerts
Copy link

omerts commented Dec 21, 2016

Hey,

I can't understand how onErrorResumeNext solves @danhyun's issue.
The source observable Rx.Observable.from([1, 2, 3, 4]), gets terminated after the error, while he (and we too), want it to continue with the next emission.
Maybe I am doing something wrong, could someone explain please?
Here is a fiddle: https://jsfiddle.net/omerts/c9ky94ac/

@omerts
Copy link

omerts commented Dec 21, 2016

Just to add, if I understood the RXJava operator right, what we need is: onExceptionResumeNext
onExceptionResumeNext - instructs an Observable to continue emitting items after it encounters an exception (but not another variety of throwable)

@gunar
Copy link

gunar commented Sep 25, 2017

You can use .catch((e, $) => $) to continue with the next value.
I've heard this is not safe to use with all Observables as it may trigger infinite loops, but seems safe for Subjects.

'use strict'

const Rx = require('rxjs')

const $ = new Rx.Subject()

const throwOnEven = x => {
  if (x % 2 === 0) throw new Error(x)
  return x
}

$
  .map(throwOnEven)
  .catch((e, stream) => stream)
  .subscribe(x => {
    console.log(`odd: ${x}`)
    // this is uncatched, still
    if (x > 4) throw Error('shit')
  }, e => {
    console.log('fatal error', e)
  })

try {
  $.next(1)
  $.next(2)
  $.next(3)
  $.next(4)
  $.next(5)
} catch (e) {
  console.log({outer:e}) // { outer: Error('shit') }
}
// odd: 1
// odd: 3
// odd: 5
// { outer: Error('shit') }

@lock
Copy link

lock bot commented Jun 6, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
help wanted Issues we wouldn't mind assistance with.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants