@graphcommerce/ecommerce-ui 7.1.0-canary.45 → 7.1.0-canary.47

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @graphcommerce/ecommerce-ui
2
2
 
3
+ ## 7.1.0-canary.47
4
+
5
+ ### Minor Changes
6
+
7
+ - [#2111](https://github.com/graphcommerce-org/graphcommerce/pull/2111) [`35f3d3eaf`](https://github.com/graphcommerce-org/graphcommerce/commit/35f3d3eaf46f4b782bb1149e0efb0ec3819442d6) - Only show network errors in development mode. ([@Jessevdpoel](https://github.com/Jessevdpoel))
8
+
9
+ ## 7.1.0-canary.46
10
+
3
11
  ## 7.1.0-canary.45
4
12
 
5
13
  ## 7.1.0-canary.38
@@ -1,6 +1,8 @@
1
1
  import { ApolloError } from '@graphcommerce/graphql'
2
2
  import { extendableComponent } from '@graphcommerce/next-ui/Styles/extendableComponent'
3
+ import { Trans } from '@lingui/react'
3
4
  import { AlertProps, Alert, Box, SxProps, Theme } from '@mui/material'
5
+ import { maskNetworkError } from './maskNetworkError'
4
6
 
5
7
  const { classes, selectors } = extendableComponent('ApolloErrorAlert', ['root', 'alert'] as const)
6
8
 
@@ -46,7 +48,7 @@ export function ApolloErrorAlert(props: ApolloErrorAlertProps) {
46
48
  key='networkError'
47
49
  >
48
50
  <Alert severity='error' {...networkErrorAlertProps}>
49
- Network Error: {error.networkError.message}
51
+ {maskNetworkError(error.networkError)}
50
52
  </Alert>
51
53
  </Box>
52
54
  </Box>
@@ -3,6 +3,7 @@ import { FullPageMessage, FullPageMessageProps } from '@graphcommerce/next-ui'
3
3
  import { Trans } from '@lingui/react'
4
4
  import { AlertProps } from '@mui/material'
5
5
  import { ApolloErrorAlert } from './ApolloErrorAlert'
6
+ import { maskNetworkError } from './maskNetworkError'
6
7
 
7
8
  export type ApolloErrorFullPageProps = {
8
9
  error: ApolloError
@@ -19,14 +20,14 @@ export function ApolloErrorFullPage(props: ApolloErrorFullPageProps) {
19
20
  ...fullPageMessageProps
20
21
  } = props
21
22
 
22
- const errorCount = error?.graphQLErrors?.length ?? +(error?.networkError ? 1 : 0)
23
+ const errorCount = (error?.graphQLErrors?.length ?? 0) + (error?.networkError ? 1 : 0)
23
24
 
24
25
  if (errorCount === 0) return null
25
26
 
26
27
  if (errorCount === 1) {
27
28
  return (
28
29
  <FullPageMessage
29
- title={error?.graphQLErrors[0].message ?? error?.networkError?.message}
30
+ title={error?.graphQLErrors?.[0]?.message ?? maskNetworkError(error.networkError)}
30
31
  {...fullPageMessageProps}
31
32
  >
32
33
  {children}
@@ -1,5 +1,6 @@
1
1
  import { ApolloError } from '@graphcommerce/graphql'
2
2
  import { ErrorSnackbar, ErrorSnackbarProps } from '@graphcommerce/next-ui'
3
+ import { maskNetworkError } from './maskNetworkError'
3
4
 
4
5
  export type ApolloErrorSnackbarProps = {
5
6
  error?: ApolloError
@@ -14,7 +15,7 @@ export function ApolloErrorSnackbar(props: ApolloErrorSnackbarProps) {
14
15
  <ErrorSnackbar variant='pill' severity='error' {...passedProps} open={!!error}>
15
16
  <>
16
17
  {error.graphQLErrors.map((e) => e.message).join(', ')}
17
- {error.networkError && <>Network Error: {error.networkError.message}</>}
18
+ {maskNetworkError(error.networkError)}
18
19
  </>
19
20
  </ErrorSnackbar>
20
21
  )
@@ -0,0 +1,26 @@
1
+ import { ServerError, ServerParseError } from '@graphcommerce/graphql'
2
+ import { Trans } from '@lingui/react'
3
+
4
+ function isServerError(error: Error | ServerParseError | ServerError | null): error is ServerError {
5
+ return 'name' in (error as ServerError)
6
+ }
7
+
8
+ function isServerParseError(
9
+ error: Error | ServerParseError | ServerError | null,
10
+ ): error is ServerParseError {
11
+ return 'bodyText' in (error as ServerParseError)
12
+ }
13
+
14
+ export function maskNetworkError(networkError: Error | ServerParseError | ServerError | null) {
15
+ if (!networkError) return null
16
+
17
+ if (isServerParseError(networkError) || isServerError(networkError)) {
18
+ return <Trans id='Something went wrong on the server, please try again later.' />
19
+ }
20
+
21
+ if (globalThis.navigator && !globalThis.navigator?.onLine) {
22
+ return <Trans id='It appears you are offline, please try again later.' />
23
+ }
24
+
25
+ return <Trans id='Something went wrong' />
26
+ }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graphcommerce/ecommerce-ui",
3
3
  "homepage": "https://www.graphcommerce.org/",
4
4
  "repository": "github:graphcommerce-org/graphcommerce",
5
- "version": "7.1.0-canary.45",
5
+ "version": "7.1.0-canary.47",
6
6
  "sideEffects": false,
7
7
  "prettier": "@graphcommerce/prettier-config-pwa",
8
8
  "eslintConfig": {
@@ -12,12 +12,12 @@
12
12
  }
13
13
  },
14
14
  "peerDependencies": {
15
- "@graphcommerce/eslint-config-pwa": "^7.1.0-canary.45",
16
- "@graphcommerce/graphql": "^7.1.0-canary.45",
17
- "@graphcommerce/next-ui": "^7.1.0-canary.45",
18
- "@graphcommerce/prettier-config-pwa": "^7.1.0-canary.45",
19
- "@graphcommerce/react-hook-form": "^7.1.0-canary.45",
20
- "@graphcommerce/typescript-config-pwa": "^7.1.0-canary.45",
15
+ "@graphcommerce/eslint-config-pwa": "^7.1.0-canary.47",
16
+ "@graphcommerce/graphql": "^7.1.0-canary.47",
17
+ "@graphcommerce/next-ui": "^7.1.0-canary.47",
18
+ "@graphcommerce/prettier-config-pwa": "^7.1.0-canary.47",
19
+ "@graphcommerce/react-hook-form": "^7.1.0-canary.47",
20
+ "@graphcommerce/typescript-config-pwa": "^7.1.0-canary.47",
21
21
  "@lingui/core": "^4.2.1",
22
22
  "@lingui/macro": "^4.2.1",
23
23
  "@lingui/react": "^4.2.1",