Skip to content

Vue managed subscription error handling #43

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

Closed
ryanrich opened this issue Jun 4, 2017 · 2 comments
Closed

Vue managed subscription error handling #43

ryanrich opened this issue Jun 4, 2017 · 2 comments

Comments

@ryanrich
Copy link

ryanrich commented Jun 4, 2017

When defining subscriptions in the subscriptions field or function there doesn't appear to be a way to attach an error handler to them. I like how convenient it is to just define an observable in these blocks and have Vue subscribe and expose the results to the component, but when subscriptions defined in this manner hit an error condition it breaks the application. Would it be possible to:

  1. Have a way to register an error handler for subscriptions that are created by Vue from this block
  2. If an error handler isn't defined, have vue route errors to the application level exception handler
@regou
Copy link
Collaborator

regou commented Jun 5, 2017

I think the 2nd one is achievable

About the first one, any suggestions? Or you can use the catch operator to do the error handling

@ryanrich
Copy link
Author

ryanrich commented Jun 12, 2017

For the first one, yes you can use catch as that is what I do now, but it is a bit more work for the cases where you just want to report an error rather than actual turn it into a retry or do some other handling as you have to return another observable from it I believe.

In terms of how best to handle it, not sure a real clean way while still maintaining backwards compatibility with what is there now. One idea would be to provide the option for people to return objects that have separate properties for the observable, onerror, oncomplete properties and then have the subscription handling code use those provided functions if they exist, otherwise assume the current type of object where it should be an observable itself.

export default {

  subscriptions() {
    const dataSub = {
        obs$: () => Observable.fromPromise(axios.get('/some/remote/data')),
        onerror: (error) => console.error('This failed', error),
        oncomplete: () => console.log('This completed')
    };
    return { dataSub };
  }
}

@regou regou mentioned this issue Sep 7, 2017
@regou regou closed this as completed Sep 12, 2017
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

2 participants