ticruz38/graphql-codegen-svelte-apollo

Error handling

i8ramin opened this issue · 2 comments

How best to deal with errors that are thrown by Apollo? For example, if I pass in an invalid auth token like so:

FindCartByUserId({
  variables: {
    userId: data.user.userId,
  },
  context: {
    headers: {
      authorization: `Bearer foo`,
    }
  }
})

I get the following error thrown, but have no way of handling it (as far as I know):

Unhandled error Invalid database secret. Error: Invalid database secret.
    at new ApolloError 

I tried to surround the code with try/catch, but it didn't seem to work. Any help would be greatly appreciated

never mind, i see the error in the error key!

FYI, I was able to get errors to come through by setting the following option on apollo client:

export default new ApolloClient({
  ...
  defaultOptions: {
    watchQuery: {
      errorPolicy: 'all',
    },
    query: {
      errorPolicy: 'all',
    },
    mutate: {
      errorPolicy: 'all',
    },
  },
})