You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm curious, how are you handling uncaught errors?
I've been getting one particular ApolloError that leads me to the mutate call inside of a graphql call, a bit low level and for some reason doesn't get caught and displayed.
Is there a way to update the data provider to catch errors and display them in the react-admin notifications?
While I would believe the data provider should likely handle this, I've been able to hook into it by customizing the apollo client to catch global errors, but I'm having trouble actually displaying a notification as I imagine there is a react-admin standard way to do this that I'm unaware of.
consterrorLink=onError(({ response, graphQLErrors, networkError })=>{if(graphQLErrors)graphQLErrors.map(({ message, locations, path, extensions })=>{if(extensions&&extensions.code==='UNAUTHENTICATED'){// edit response so downstream can cat an error messageresponse.errors=[newError('UNAUTHENTICATED')];}else{// WE COULD RENDER THE NOTIFICATION HEREconsole.log(`[NOTIFICATION]: ${extensions?.code||message}`);}console.log(`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`);});if(networkError)console.log(`[Network error]: ${networkError}`);});constlink=from([authLink,errorLink,createUploadLink({
uri
}),newHttpLink({
uri,credentials: 'include'})]);constclient=newApolloClient({
link,cache: newInMemoryCache(),defaultOptions: {watchQuery: {fetchPolicy: 'no-cache',errorPolicy: 'ignore'},query: {fetchPolicy: 'no-cache',errorPolicy: 'all'}}});
The text was updated successfully, but these errors were encountered:
As you create the apollo client in the react root application, you could technically pass a callback and do custom client side notifications. As those are just using the standard material-ui notification components, you could use them to show a custom error notification or handle a login for example.
For authentication though I actually wrap the Root application into a hoc which does a graphql query to check the authentication state with errorPolicy: 'all'. And if the user is not logged in I (in my case) do a redirect to the oauth flow.
I think the issue is that some of the errors aren't getting caught in the right place for the app.
For me authentication is an easy redirect we can handle, but other simple errors are causing issues. For example, if you make a unique constraint on a postgres table, and try to insert a record that would create an error on the unique index, the ra-postgraphile and react-admin just throw an error in the console.
Ideally in the example of a unique index or any index error, would be great to propagate the error message into the normal error system that react admin seems to have in place.
This one example of unique indexes feels decently normal case to solve without special cases, I'm happy to make a PR or something if you can point me to the right place.
I'm curious, how are you handling uncaught errors?
I've been getting one particular
ApolloError
that leads me to themutate
call inside of a graphql call, a bit low level and for some reason doesn't get caught and displayed.Is there a way to update the data provider to catch errors and display them in the react-admin notifications?
While I would believe the data provider should likely handle this, I've been able to hook into it by customizing the apollo client to catch global errors, but I'm having trouble actually displaying a notification as I imagine there is a react-admin standard way to do this that I'm unaware of.
The text was updated successfully, but these errors were encountered: