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

Global userbase error handler #4

Open
Saunved opened this issue Nov 5, 2020 · 2 comments
Open

Global userbase error handler #4

Saunved opened this issue Nov 5, 2020 · 2 comments
Assignees

Comments

@Saunved
Copy link

Saunved commented Nov 5, 2020

Hi, thanks for making this module!
I was wondering if it is possible for us to have a global error handler for Userbase in this?
Or is this something that Userbase has to implement in the SDK?

@ceigh
Copy link
Owner

ceigh commented Nov 5, 2020

@Saunved Hi! Can you show any of the situations you are talking about or code examples? Right now I don't know what you're talking about.

@ceigh ceigh self-assigned this Nov 5, 2020
@Saunved
Copy link
Author

Saunved commented Nov 5, 2020

Hey, you can check this link for Axios interceptors. I was wondering if there's some mechanism to intercept errors that Userbase throws (globally).

Here's an example:

this.$userbase.updateUser({
  ...someData
}).then(() => {
  // do something
 }).catch((e) => {
   this.$eventBus.$emit('userbase-error', e);
})

If one has many such calls spread throughout the application, dealing with the error at each call is quite cumbersome. Instead, if we could intercept the error in a plugin (like we can with Axios), it can be dealt with in a generic manner.

My solution for now is to emit an event inside the catch and deal with the error event inside a plugin.

// The userbase function call
this.$userbase.updateUser({
  ...someData
}).then(() => {
  // do something
 }).catch((e) => {
   this.$eventBus.$emit('userbase-error', e);
}) 
// userbase-error.js plugin
import Vue from 'vue'
export default async function ({ app }, inject) {

  inject('eventBus', new Vue());  // inject eventBus to emit the event later

  app.$eventBus.$on('userbase-error', (err) => {
    // Deal with the error in a generic fashion - maybe show a snackbar or a toast
  }
}

This can also be done using mixins (and using this.$nuxt.$emit) instead of injecting the event bus.
If Userbase had such a mechanism or if this module can implement it, that'd be awesome.

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

2 participants