Nuxt and Vue Apollo. How to handle errors inside Smart Query with redirection to 404/400/500 error page? Can we catch such errors?

With regular HTTP request, we may create redirection with asyncData({error}){…}

What should we use for redirecting to 400 page using Smart Query?

With Vue Apollo, I am trying to use

    apollo: {
        queryName: {
            prefetch: true,
            query: wrongQuery,
    
            error(errorData) {
                this.$nuxt.error({
                    statusCode: 500,
                    message: 'Error message',
                });
            },
        },
    };

In case if we reload the page, redirection doesn’t work. We still got an error becouse server side rendering:

enter image description here

With global error handler like:

    // /plugins/apollo-error-handler.js
    export default ({ graphQLErrors, networkError, operation, forward }, nuxtContext) => {
        console.log(networkError)
        nuxtContext.error({
          statusCode: 404,
          message: 'Error message',
        });
    };

Only errors logging works. Redirection doesn’t work at all.

Do we have any way to handle errors inside smart queries with redirection to 400 page for example?

Can we catch such errors in smart query? Like try…catch… in asyncData() to prevent app crash.

34 thoughts on “Nuxt and Vue Apollo. How to handle errors inside Smart Query with redirection to 404/400/500 error page? Can we catch such errors?”

  1. 872117 995336Keep in touch whilst functioning from your personal home office with out all with the hassle of purchasing or procurment costly workplace equipment. Debtors are allowed to apply with their a bad credit score background whenever. 46261

    Reply
  2. 61964 448924Aw, this became an very good post. In thought I would like to devote writing such as this moreover – taking time and actual effort to make a extremely great article but exactly what do I say I procrastinate alot and by no means locate a method to get something completed. 1565

    Reply
  3. Pingback: ebony sex games

Leave a Comment