-
Notifications
You must be signed in to change notification settings - Fork 0
Global userbase error handler #4
Comments
@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. |
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. |
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?
The text was updated successfully, but these errors were encountered: