I'm trying to use vue-apollo with SSR rendering, but when query is succesfull and I have an error in data update hook, my code just exits with an error.
I configured my app according to vue-apollo SSR guide with bundledRenderer.
But the following code just exits the application:
<template>
<ul>
<li v-for="(offer, index) in offers" v-bind:key="index">
{{ offer.title }}
</li>
</ul>
</template>
<script lang="ts">
import Vue from 'vue';
import gql from 'graphql-tag';
export default {
apollo: {
offers: {
query: gql`
{
offers {
id
title
}
}
`,
update(data) {
throw new Error('error');
},
},
},
}
</script>
with following error:
Error: error
at VueComponent.update (webpack-internal:///LWFF:10:23)
at SmartQuery.nextResult (~/project/node_modules/vue-apollo/dist/vue-apollo.umd.js:822:44)
at notifySubscription (~/project/node_modules/apollo-link/node_modules/zen-observable/lib/Observable.js:126:18)
at flushSubscription (~/project/node_modules/apollo-link/node_modules/zen-observable/lib/Observable.js:112:5)
at ~/project/node_modules/apollo-link/node_modules/zen-observable/lib/Observable.js:156:14
at ~/project/node_modules/apollo-link/node_modules/zen-observable/lib/Observable.js:67:7
at <anonymous>
at process._tickDomainCallback (internal/process/next_tick.js:228:7)
I tried to catch that error after renderToString function with Promise.catch.
It is caught, but somehow there is same error, that propagetes thru all stack ending my node process.
Can't find the way to intercept this error, except than in update hook.
Sorry for the wrong issue.
Actually it's zen-observable throwing error on setTimeout:
https://github.com/zenparsing/zen-observable/blob/master/src/Observable.js#L44
Actually I think that this should be reopened.
If the error thrown here:
https://github.com/Akryum/vue-apollo/blob/master/src/smart-query.js#L135
there is no way to catch it.
You can patch this by creating a mixin that wraps every update method on an apollo query with a try-catch-block.
It would be great to have this build in.
I am having similar issues. I am trying to throw/signal an error from a component to the _renderer.renderToString(...)_ so I can make a redirect (server side). It seems that _renderToString_ will never see the errors thrown in the apollo handles and the server exits instead.
Most helpful comment
You can patch this by creating a mixin that wraps every update method on an apollo query with a try-catch-block.
It would be great to have this build in.