Fix network error handling (#3406)

This commit is contained in:
Paweł Chyła 2023-04-12 09:46:11 +02:00 committed by GitHub
parent 63b98a08bf
commit 935c224bb2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View file

@ -18,9 +18,9 @@ export const displayDemoMessage = (
const getNetworkErrors = (error: ApolloError): string[] => {
const networkErrors = error.networkError as ServerError;
if (networkErrors) {
// Apparently network errors can be an object or an array
if (Array.isArray(networkErrors.result)) {
networkErrors.result.forEach(result => {
if (result.errors) {
@ -29,6 +29,10 @@ const getNetworkErrors = (error: ApolloError): string[] => {
});
}
if (networkErrors.result?.errors) {
return networkErrors.result.errors.map(({ message }) => message);
}
return [networkErrors.message];
}

View file

@ -66,7 +66,7 @@ export function useMutation<TData, TVariables>(
},
onError: (err: ApolloError) => {
if (!disableErrorHandling) {
if (err.graphQLErrors) {
if (err?.graphQLErrors.length > 0) {
if (hasError(err, GqlErrors.ReadOnlyException)) {
notify({
status: "error",