set up global error handling

This commit is contained in:
fmtabbara
2021-09-10 09:56:04 +01:00
parent 0c9cf7b5d9
commit 37da23ab1c
5 changed files with 45 additions and 8 deletions
+1
View File
@@ -20,6 +20,7 @@
"clsx": "^1.1.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-error-boundary": "^3.1.3",
"react-hook-form": "^7.14.2",
"react-router-dom": "^5.2.0",
"semver": "^6.3.0",
+20
View File
@@ -0,0 +1,20 @@
import React from 'react'
import { FallbackProps } from 'react-error-boundary'
import { Alert, AlertTitle } from '@material-ui/lab'
import { Button } from '@material-ui/core'
export const ErrorFallback = ({ error, resetErrorBoundary }: FallbackProps) => {
return (
<div>
<Alert severity="error">
<AlertTitle>{error.name}</AlertTitle>
{error.message}
</Alert>
<Alert severity="error">
<AlertTitle>Stack trace</AlertTitle>
{error.stack}
</Alert>
<Button onClick={resetErrorBoundary}>Back to safety</Button>
</div>
)
}
+6 -1
View File
@@ -1,4 +1,9 @@
export * from './NymCard'
export * from './Error'
export * from './Confirmation'
export * from './CopyToClipboard'
export * from './NymCard'
export * from './Nav'
export * from './NavigationCards'
export * from './NodeTypeSelector'
export * from './RequestStatus'
export * from './NoClientError'
+9 -5
View File
@@ -1,5 +1,6 @@
import React, { useContext } from 'react'
import ReactDOM from 'react-dom'
import { ErrorBoundary } from 'react-error-boundary'
import { CssBaseline, ThemeProvider } from '@material-ui/core'
import { BrowserRouter as Router } from 'react-router-dom'
import { Routes } from './routes'
@@ -7,6 +8,7 @@ import { theme } from './theme'
import { ClientContext, ClientContextProvider } from './context/main'
import { ApplicationLayout } from './layouts'
import { SignIn } from './routes/sign-in'
import { ErrorFallback } from './components'
const AppWrapper = () => {
const { clientDetails } = useContext(ClientContext)
@@ -26,11 +28,13 @@ const AppWrapper = () => {
const App = () => {
return (
<Router>
<ClientContextProvider>
<AppWrapper />
</ClientContextProvider>
</Router>
<ErrorBoundary FallbackComponent={ErrorFallback}>
<Router>
<ClientContextProvider>
<AppWrapper />
</ClientContextProvider>
</Router>
</ErrorBoundary>
)
}
+9 -2
View File
@@ -906,7 +906,7 @@
"@babel/helper-validator-option" "^7.14.5"
"@babel/plugin-transform-typescript" "^7.15.0"
"@babel/runtime@^7.1.2", "@babel/runtime@^7.10.5", "@babel/runtime@^7.12.1", "@babel/runtime@^7.3.1", "@babel/runtime@^7.4.4", "@babel/runtime@^7.5.5", "@babel/runtime@^7.7.2", "@babel/runtime@^7.8.3", "@babel/runtime@^7.8.4", "@babel/runtime@^7.8.7":
"@babel/runtime@^7.1.2", "@babel/runtime@^7.10.5", "@babel/runtime@^7.12.1", "@babel/runtime@^7.12.5", "@babel/runtime@^7.3.1", "@babel/runtime@^7.4.4", "@babel/runtime@^7.5.5", "@babel/runtime@^7.7.2", "@babel/runtime@^7.8.3", "@babel/runtime@^7.8.4", "@babel/runtime@^7.8.7":
"integrity" "sha512-OvwMLqNXkCXSz1kSm58sEsNuhqOx/fKpnUnKnFB5v8uDda5bLNEHNgKPvhDN6IU0LDcnHQ90LlJ0Q6jnyBSIBA=="
"resolved" "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.15.3.tgz"
"version" "7.15.3"
@@ -6231,6 +6231,13 @@
"object-assign" "^4.1.1"
"scheduler" "^0.20.2"
"react-error-boundary@^3.1.3":
"integrity" "sha512-A+F9HHy9fvt9t8SNDlonq01prnU8AmkjvGKV4kk8seB9kU3xMEO8J/PQlLVmoOIDODl5U2kufSBs4vrWIqhsAA=="
"resolved" "https://registry.npmjs.org/react-error-boundary/-/react-error-boundary-3.1.3.tgz"
"version" "3.1.3"
dependencies:
"@babel/runtime" "^7.12.5"
"react-hook-form@^7.0.0", "react-hook-form@^7.14.2":
"integrity" "sha512-32uvgKkaE/0vOncfnJdwQhfahhocPpcb5c7F4j9Eq7dOnqS2Hg8h70Bmt6KXb6veLSWJultc1+ik9QSfqXFmLA=="
"resolved" "https://registry.npmjs.org/react-hook-form/-/react-hook-form-7.14.2.tgz"
@@ -6280,7 +6287,7 @@
"loose-envify" "^1.4.0"
"prop-types" "^15.6.2"
"react@^0.14.0 || ^15.0.0 || ^16.0.0 || ^17.0.0", "react@^16.8.0 || ^17", "react@^16.8.0 || ^17.0.0", "react@^17.0.2", "react@>=15", "react@>=16.6.0", "react@17.0.2":
"react@^0.14.0 || ^15.0.0 || ^16.0.0 || ^17.0.0", "react@^16.8.0 || ^17", "react@^16.8.0 || ^17.0.0", "react@^17.0.2", "react@>=15", "react@>=16.13.1", "react@>=16.6.0", "react@17.0.2":
"integrity" "sha512-gnhPt75i/dq/z3/6q/0asP78D0u592D5L1pd7M8P+dck6Fu/jJeL6iVVK23fptSUZj8Vjf++7wXA8UNclGQcbA=="
"resolved" "https://registry.yarnpkg.com/react/-/react-17.0.2.tgz"
"version" "17.0.2"