Skip to content
This repository has been archived by the owner on Sep 10, 2022. It is now read-only.

Throw errors from stream in render()? #547

Open
spalger opened this issue Oct 26, 2017 · 2 comments
Open

Throw errors from stream in render()? #547

spalger opened this issue Oct 26, 2017 · 2 comments

Comments

@spalger
Copy link
Contributor

spalger commented Oct 26, 2017

I'm trying out componentFromStream() and was surprised to learn that errors are being swallowed when they bubble up to recompose because it does not subscribe to errors here, only next: notifications.

I'd be happy to submit a pr if others think this would work:

componentWillMount() {
  // Subscribe to child prop changes so we know when to re-render
  this.subscription = this.vdom$.subscribe({
    next: vdom => {
      this.setState({ vdom })
    },
    error: thrown => {
      this.setState({ thrown })
    }
  })
  this.propsEmitter.emit(this.props)
}

// ...

render() {
  if (this.state.thrown) {
    throw this.state.thrown
  } else {
    return this.state.vdom
  }
}
@istarkov
Copy link
Contributor

As I remember errors are visible in console (not for all frameworks but for rxjs are)
This will allow to throw error independently of stream framework, and also to intercept error using modern 16 api.
At a first sight I see nothing bad in you suggestion. @wuct others?

@wuct
Copy link
Contributor

wuct commented Oct 27, 2017

Looks good to me. IMO this is the right way to handle error.

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

No branches or pull requests

3 participants