Error handling
i8ramin opened this issue · 2 comments
i8ramin commented
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
i8ramin commented
never mind, i see the error in the error key!
i8ramin commented
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',
},
},
})