I have a React application which I've surrounded with an ErrorBoundary
that sends errors to Sentry and it works fine. I would like to log all my GraphQL query errors into Sentry as well but my problem now is for all my GraphQL queries, I have a catch block where I dispatch an action for the failed query.
When I remove the catch blocks, the errors are logged into Sentry but I'm unable to trigger the failed query action.
My solution now is to put Sentry.captureException()
into each catch block of a GraphQL query which is very repetitive.
Is there a way to allow the ErrorBoundary
to still catch GraphQL errors even if the query has it's own catch block?
function getEmployee() {
return function(dispatch) {
dispatch(requestEmployeeInformation());
GraphqlClient.query({ query: EmployeeQuery, fetchPolicy: 'network-only' })
.then((response) => {
dispatch(receiveEmployeeInformation(response.data));
})
.catch((error) => {
/* temporary solution. This sends error to sentry but is very repetitive because
it has to be added to every single action with a graphql query
*/
Sentry.captureException(error)
//dispatch this action if the query failed
dispatch(failGetEmployee(error));
});
};
}