From 3a5791e796cd3b0981aff13d0b765c59eff85193 Mon Sep 17 00:00:00 2001 From: dominik-zeglen Date: Mon, 11 May 2020 17:19:36 +0200 Subject: [PATCH 1/2] DIsplay correct error if there were no gql errors --- src/hooks/makeMutation.ts | 2 +- src/hooks/makeQuery.ts | 2 +- src/mutations.tsx | 16 +++++++++------- src/queries.tsx | 2 +- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/hooks/makeMutation.ts b/src/hooks/makeMutation.ts index 1bda2b926..0bd2c2eb5 100644 --- a/src/hooks/makeMutation.ts +++ b/src/hooks/makeMutation.ts @@ -50,7 +50,7 @@ function makeMutation( notify({ text: intl.formatMessage(commonMessages.readOnly) }); - } else if (err.graphQLErrors.every(isJwtError)) { + } else if (err.graphQLErrors.some(isJwtError)) { user.logout(); notify({ text: intl.formatMessage(commonMessages.sessionExpired) diff --git a/src/hooks/makeQuery.ts b/src/hooks/makeQuery.ts index e5ff1703c..beddd14df 100644 --- a/src/hooks/makeQuery.ts +++ b/src/hooks/makeQuery.ts @@ -64,7 +64,7 @@ function makeQuery( }, [queryData.loading]); if (queryData.error) { - if (queryData.error.graphQLErrors.every(isJwtError)) { + if (queryData.error.graphQLErrors.some(isJwtError)) { user.logout(); notify({ text: intl.formatMessage(commonMessages.sessionExpired) diff --git a/src/mutations.tsx b/src/mutations.tsx index 727a9d8e0..f685c6cb8 100644 --- a/src/mutations.tsx +++ b/src/mutations.tsx @@ -6,7 +6,7 @@ import { useIntl } from "react-intl"; import useNotifier from "./hooks/useNotifier"; import { commonMessages } from "./intl"; -import { maybe, getMutationStatus } from "./misc"; +import { getMutationStatus } from "./misc"; import { MutationResultAdditionalProps } from "./types"; import { isJwtError } from "./auth/errors"; import useUser from "./hooks/useUser"; @@ -37,17 +37,19 @@ export function TypedMutation( mutation={mutation} onCompleted={onCompleted} onError={(err: ApolloError) => { + if (err.networkError) { + notify({ + text: intl.formatMessage(commonMessages.somethingWentWrong) + }); + } if ( - maybe( - () => - err.graphQLErrors[0].extensions.exception.code === - "ReadOnlyException" - ) + err.graphQLErrors[0].extensions.exception?.code === + "ReadOnlyException" ) { notify({ text: intl.formatMessage(commonMessages.readOnly) }); - } else if (err.graphQLErrors.every(isJwtError)) { + } else if (err.graphQLErrors.some(isJwtError)) { user.logout(); notify({ text: intl.formatMessage(commonMessages.sessionExpired) diff --git a/src/queries.tsx b/src/queries.tsx index 952c943d8..708aa27b1 100644 --- a/src/queries.tsx +++ b/src/queries.tsx @@ -83,7 +83,7 @@ export function TypedQuery( > {(queryData: QueryResult) => { if (queryData.error) { - if (queryData.error.graphQLErrors.every(isJwtError)) { + if (queryData.error.graphQLErrors.some(isJwtError)) { user.logout(); notify({ text: intl.formatMessage(commonMessages.sessionExpired) From 34c78b7da3e512af6e0f0e10d86ee4826f6498fb Mon Sep 17 00:00:00 2001 From: dominik-zeglen Date: Mon, 11 May 2020 17:25:18 +0200 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index aba8eecf2..a790e41ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,6 +51,7 @@ All notable, unreleased changes to this project will be documented in this file. - Fix minor visual bugs - #521 by @dominik-zeglen - Handle session expiration - #520 by @dominik-zeglen - Update product stock management to newest design - #515 by @dominik-zeglen +- Display correct error if there were no graphql errors - #525 by @dominik-zeglen ## 2.0.0