Skip to content

Commit

Permalink
fix(error): fix generic error boundary message (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
sijav authored Nov 20, 2023
1 parent 6517ae5 commit de6bd15
Show file tree
Hide file tree
Showing 13 changed files with 105 additions and 19 deletions.
3 changes: 2 additions & 1 deletion .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ VITE_NETWORK_RETRY_COUNT=5
VITE_WEBSOCKET_RETRY_TIMEOUT=5000
HOST=127.0.0.1
PORT=8081
VITE_USE_MOCK=false
VITE_USE_MOCK=false
VITE_DISCORD_URL=https://discord.gg/someengineering
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ VITE_NETWORK_RETRY_COUNT=5
VITE_WEBSOCKET_RETRY_TIMEOUT=5000
HOST=127.0.0.1
PORT=8081
VITE_USE_MOCK=false
VITE_USE_MOCK=false
VITE_DISCORD_URL=https://discord.gg/someengineering
1 change: 1 addition & 0 deletions .env.production
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ VITE_USE_PROXY=false
VITE_NETWORK_RETRY_COUNT=5
VITE_WEBSOCKET_RETRY_TIMEOUT=5000
VITE_USE_MOCK=false
VITE_DISCORD_URL=https://discord.gg/someengineering
3 changes: 2 additions & 1 deletion .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ VITE_NETWORK_RETRY_COUNT=5
VITE_WEBSOCKET_RETRY_TIMEOUT=5000
HOST=127.0.0.1
PORT=8081
VITE_USE_MOCK=true
VITE_USE_MOCK=true
VITE_DISCORD_URL=https://discord.gg/someengineering
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn lint-staged
# yarn lint-staged
3 changes: 3 additions & 0 deletions src/assets/icons/discord-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion src/assets/icons/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import AwsLogo from './aws-logo.svg?react'
import DiscrodIcon from './discord-icon.svg?react'
import FixLogo from './fix-logo.svg?react'
import GcpLogo from './gcp-logo.svg?react'
import GithubSEBIcon from './github-seb-icon.svg?react'
import GoogleSEBIcon from './google-seb-icon.svg?react'
import LogoWhiteNoBackground from './logo-white-no-background.svg?react'

export { AwsLogo, FixLogo, GcpLogo, GithubSEBIcon, GoogleSEBIcon, LogoWhiteNoBackground }
export { AwsLogo, DiscrodIcon, FixLogo, GcpLogo, GithubSEBIcon, GoogleSEBIcon, LogoWhiteNoBackground }
12 changes: 12 additions & 0 deletions src/locales/de-DE/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,10 @@ msgstr "Keine Änderungen"
msgid "Nothing to show yet"
msgstr "Noch nichts zu zeigen"

#: src/shared/error-boundary-fallback/ErrorBoundaryFallback.tsx:32
msgid "Oops! Something went wrong."
msgstr "Hoppla! Etwas ist schief gelaufen."

#: src/shared/layouts/panel-layout/PanelAppBar.tsx:69
msgid "Open drawer"
msgstr "Öffene die Schublade"
Expand Down Expand Up @@ -431,6 +435,10 @@ msgstr "Top Ressourcen mit Compliance-Verstößen"
msgid "True"
msgstr "WAHR"

#: src/shared/error-boundary-fallback/ErrorBoundaryFallback.tsx:58
msgid "Try again"
msgstr "Versuchen Sie es erneut"

#: src/pages/panel/inventory/InventoryFormFilterRow.tsx:159
#: src/pages/panel/inventory/InventoryFormFilterRow.tsx:167
#: src/pages/panel/inventory/utils/getAutoCompleteFromKey.tsx:91
Expand All @@ -441,6 +449,10 @@ msgstr "Wert"
msgid "We have sent an email with a confirmation link to your email address. Please follow the link to activate your account."
msgstr "Wir haben eine E-Mail mit einem Bestätigungslink an Ihre E-Mail-Adresse gesendet. Bitte folgen Sie dem Link, um Ihr Konto zu aktivieren."

#: src/shared/error-boundary-fallback/ErrorBoundaryFallback.tsx:35
msgid "We're sorry for the inconvenience. Our team has been notified, and the issue is being looked into. Please try again in a few minutes. If the problem persists, feel free to contact us <0>on Discord</0>. Thanks for your patience!"
msgstr "Wir entschuldigen uns für die Unannehmlichkeiten. Unser Team wurde benachrichtigt und das Problem wird untersucht. Bitte versuchen Sie es in ein paar Minuten noch einmal. Wenn das Problem weiterhin besteht, können Sie uns gerne <0>auf Discord</0> kontaktieren. Danke für Ihre Geduld!"

#: src/pages/auth/login/LoginPage.tsx:126
msgid "You have successfully verified your account."
msgstr "Sie haben Ihr Konto erfolgreich verifiziert."
Expand Down
12 changes: 12 additions & 0 deletions src/locales/en-US/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,10 @@ msgstr "No changes"
msgid "Nothing to show yet"
msgstr "Nothing to show yet"

#: src/shared/error-boundary-fallback/ErrorBoundaryFallback.tsx:32
msgid "Oops! Something went wrong."
msgstr "Oops! Something went wrong."

#: src/shared/layouts/panel-layout/PanelAppBar.tsx:69
msgid "Open drawer"
msgstr "Open drawer"
Expand Down Expand Up @@ -431,6 +435,10 @@ msgstr "Top Non-Compliant Resources"
msgid "True"
msgstr "True"

#: src/shared/error-boundary-fallback/ErrorBoundaryFallback.tsx:58
msgid "Try again"
msgstr "Try again"

#: src/pages/panel/inventory/InventoryFormFilterRow.tsx:159
#: src/pages/panel/inventory/InventoryFormFilterRow.tsx:167
#: src/pages/panel/inventory/utils/getAutoCompleteFromKey.tsx:91
Expand All @@ -441,6 +449,10 @@ msgstr "Value"
msgid "We have sent an email with a confirmation link to your email address. Please follow the link to activate your account."
msgstr "We have sent an email with a confirmation link to your email address. Please follow the link to activate your account."

#: src/shared/error-boundary-fallback/ErrorBoundaryFallback.tsx:35
msgid "We're sorry for the inconvenience. Our team has been notified, and the issue is being looked into. Please try again in a few minutes. If the problem persists, feel free to contact us <0>on Discord</0>. Thanks for your patience!"
msgstr "We're sorry for the inconvenience. Our team has been notified, and the issue is being looked into. Please try again in a few minutes. If the problem persists, feel free to contact us <0>on Discord</0>. Thanks for your patience!"

#: src/pages/auth/login/LoginPage.tsx:126
msgid "You have successfully verified your account."
msgstr "You have successfully verified your account."
Expand Down
1 change: 1 addition & 0 deletions src/shared/constants/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ export const env = {
: import.meta.env.VITE_WS_SERVER ?? import.meta.env.VITE_SERVER?.replace('http', 'ws') ?? wsOrigin,
retryCount: envToNumber(import.meta.env.VITE_NETWORK_RETRY_COUNT) ?? 5,
webSocketRetryTimeout: envToNumber(import.meta.env.VITE_WEBSOCKET_RETRY_TIMEOUT) ?? 5_000,
discordUrl: import.meta.env.VITE_DISCORD_URL ?? '#',
}
65 changes: 58 additions & 7 deletions src/shared/error-boundary-fallback/ErrorBoundaryFallback.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,64 @@
import { Box, Button, Typography } from '@mui/material'
import { Trans } from '@lingui/macro'
import BuildIcon from '@mui/icons-material/Build'
import { Button, Divider, Link, Modal, Stack, Typography, styled } from '@mui/material'
import { useEffect } from 'react'
import { FallbackProps } from 'react-error-boundary'
import { DiscrodIcon } from 'src/assets/icons'
import { env } from 'src/shared/constants'

const ModalContent = styled(Stack)(({ theme }) => ({
position: 'absolute',
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)',
width: '600px',
maxWidth: `calc(100% - ${theme.spacing(2)}px)`,
backgroundColor: theme.palette.background.paper,
borderRadius: 4,
boxShadow: theme.shadows[24],
padding: theme.spacing(2, 4, 3),
}))

export const ErrorBoundaryFallback = ({ error, resetErrorBoundary }: FallbackProps) => {
useEffect(() => {
console.error(error)
}, [error])

return (
<Box display="flex" flexDirection="column" p={2}>
<Typography color="error">{(error as Error).message}</Typography>
<Button onClick={resetErrorBoundary} variant="contained" sx={{ mt: 1 }} color="warning">
Reset
</Button>
</Box>
<Modal open onClose={resetErrorBoundary} aria-labelledby="modal-error-title" aria-describedby="modal-error-description">
<ModalContent spacing={2}>
<Typography id="modal-error-title" variant="h5" component={Stack} alignItems="center" direction="row">
<BuildIcon color="error" sx={{ mr: 1 }} />
<Trans>Oops! Something went wrong.</Trans>
</Typography>
<Typography id="modal-error-description" textAlign="justify" mb={1}>
<Trans>
We're sorry for the inconvenience. Our team has been notified, and the issue is being looked into. Please try again in a few
minutes. If the problem persists, feel free to contact us{' '}
<Link href={env.discordUrl} target="_blank">
on Discord
</Link>
. Thanks for your patience!
</Trans>
</Typography>
<Divider />
<Stack spacing={1} justifyContent="end" direction="row">
<Button
onClick={resetErrorBoundary}
variant="contained"
sx={{ mt: 1 }}
color="primary"
startIcon={<DiscrodIcon />}
href={env.discordUrl}
target="_blank"
>
Discord
</Button>
<Button onClick={resetErrorBoundary} variant="outlined" sx={{ mt: 1 }} color="warning">
<Trans>Try again</Trans>
</Button>
</Stack>
</ModalContent>
</Modal>
)
}
5 changes: 3 additions & 2 deletions src/shared/modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ const ModalContent = styled(Stack)(({ theme }) => ({
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)',
width: 400,
background: theme.palette.background.paper,
width: '400px',
maxWidth: `calc(100% - ${theme.spacing(2)}px`,
backgroundColor: theme.palette.background.paper,
borderRadius: 4,
boxShadow: theme.shadows['24'],
padding: theme.spacing(2, 4, 3),
Expand Down
11 changes: 6 additions & 5 deletions src/shared/types/global/react-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/// <reference types="vite/client" />

interface ImportMetaEnv {
readonly VITE_SERVER: string
readonly VITE_WS_SERVER: string
readonly VITE_USE_PROXY: string
readonly VITE_NETWORK_RETRY_COUNT: string
readonly VITE_WEBSOCKET_RETRY_TIMEOUT: string
readonly VITE_SERVER?: string
readonly VITE_WS_SERVER?: string
readonly VITE_USE_PROXY?: string
readonly VITE_NETWORK_RETRY_COUNT?: string
readonly VITE_WEBSOCKET_RETRY_TIMEOUT?: string
readonly VITE_DISCORD_URL?: string
}

interface ImportMeta {
Expand Down

0 comments on commit de6bd15

Please sign in to comment.