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

Subscribe() suppresses errors #500

Closed
mattcodez opened this issue May 24, 2016 · 2 comments
Closed

Subscribe() suppresses errors #500

mattcodez opened this issue May 24, 2016 · 2 comments

Comments

@mattcodez
Copy link

Server: 1.0.2
Client: Whatever that server version sends

So, I was having a recurring error in a subscribe() callback but had no way of knowing. Even adding an error callback does nothing. Some trimmed code from my application:

hz.currentUser().fetch().subscribe(user => {
      console.log('hi');
      throw 'test';
      console.log('foo');
    }, err => console.error(err), ()=>console.log('done!'));

Results in 'hi' being logged in the console but nothing else and no errors being thrown in Chrome 50. Note, code is being eval()'ed after a Babel transpile.

@danielmewes
Copy link
Member

Note that subscribe is a method from RxJS: http://reactivex.io/rxjs/class/es6/Observable.js~Observable.html#instance-method-subscribe

Their documentation doesn't seem to specify how exceptions thrown in one of the callbacks are handled, so I'm not sure if this is intended behavior from their side or not.

@marshall007
Copy link
Contributor

@mattcodez see ReactiveX/rxjs#1135. Errors thrown in the next callback are not propagated to the subscription's error handler. As an alternative, you can use .forEach which returns a Promise and is rejected when any error is thrown on the subscription or in the next callback.

hz.currentUser().fetch().forEach(user => {
  console.log('hi');
  throw 'test';
  console.log('foo');
})
.catch(err => console.error(err))
.then(() => console.log('done!'))

If you prefer a solution that only uses Observables, you can use the .do() operator in place of the next handler:

hz.currentUser().fetch().do(user => {
  console.log('hi');
  throw 'test';
  console.log('foo');
})
.subscribe(null, err => console.error(err), () => console.log('done!'))

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

No branches or pull requests

4 participants