Skip to content
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

Rendering errors during SSR #585

Open
ulich opened this issue Apr 23, 2019 · 4 comments
Open

Rendering errors during SSR #585

ulich opened this issue Apr 23, 2019 · 4 comments

Comments

@ulich
Copy link

ulich commented Apr 23, 2019

I am using 3.0.0-beta.28.

If a graphql query is rejected with (e.g. network) errors, i want to render an error message in the component that initiated the query. This works fine on the client side with

  apollo: {
    messages: {
      query: messages,
      error(e) {
        this.error = e
      }
    }
  },
<div v-if="error">Oops. Something went wrong</div>

but when this component is rendered on the server it leads to a rejected serverPrefetch, which in turn stops the rendering of any component that comes after the current component.

What is the general idea on handling errors during server side rendering? When looking at the code, this seems to be implemented on purpose exactly how i experienced it.

My setup is a clean vue-cli 3 project:

vue create ...
vue add apollo
vue add @akryum/ssr

In version 3.0.0-beta.27 it works

@jeissler
Copy link

@Akryum Is there any resolve to this? I'm facing the very same issue on v3.0.3 and can't find any way around it when using server prefetch which we have to use. Any further info on this is very much appreciated!

@robere2
Copy link

robere2 commented May 12, 2020

This issue is awfully quiet. Is this intentional? Is there some workaround? I've spent a few hours digging and haven't been able to come up with a good solution yet besides completely disabling prefetching, which isn't ideal... I attempted to write server middleware which would respond with a 200 response code, but as you might expect, the issue is whenever an error is present in the errors response and not just the HTTP code. Ideally I think the server should try to fill the data, and if it can't, then the client should try again.

robere2 added a commit to rpitv/glimpse-ui that referenced this issue May 12, 2020
@MrWook
Copy link

MrWook commented May 13, 2020

I created a PR some time ago that will fix this issue but sadly there wasn't any response to it. #874

As a workaround a colleague of mine created this global mixin that will catch those errors and will log it:

export default {
  install(Vue) {
    Vue.mixin({
      beforeCreate() {
        // Prepare properties
        const { apollo } = this.$options

        if (!apollo) {
          return
        }

        // go through all queries
        Object.keys(apollo)
          .filter(key => key.charAt(0) !== '$')
          .forEach(key => {
            const options = apollo[key]
            const oldFn = options.update

            // check if update hook exists and has not already been wrapped
            if (options.update && !options.update.wrapped) {
              options.update = function safeApolloUpdate(...args) {
                try {
                  // call original function
                  return oldFn.call(this, ...args)
                } catch (e) {
                  logger.log('error', 'APOLLO_UPDATE_ERROR', {
                    message: e.message,
                    error: e,
                    data: {
                      component: this.$options ? this.$options.name : 'unknown',
                      apolloKey: key,
                      apolloResponse: { ...args },
                    },
                  })
                }
                return undefined
              }
              options.update.wrapped = true
            }
          })
      },
    })
  },
}

@thevalleydev
Copy link

I am using 3.0.0-beta.28.

If a graphql query is rejected with (e.g. network) errors, i want to render an error message in the component that initiated the query. This works fine on the client side with

  apollo: {
    messages: {
      query: messages,
      error(e) {
        this.error = e
      }
    }
  },
<div v-if="error">Oops. Something went wrong</div>

but when this component is rendered on the server it leads to a rejected serverPrefetch, which in turn stops the rendering of any component that comes after the current component.

What is the general idea on handling errors during server side rendering? When looking at the code, this seems to be implemented on purpose exactly how i experienced it.

My setup is a clean vue-cli 3 project:

vue create ...
vue add apollo
vue add @akryum/ssr

In version 3.0.0-beta.27 it works

Did you ever find a way to handle SSR errors with vue-apollo?

robere2 added a commit to rpitv/glimpse that referenced this issue Dec 15, 2023
robere2 added a commit to rpitv/glimpse that referenced this issue Dec 15, 2023
robere2 added a commit to rpitv/glimpse that referenced this issue Dec 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants