mirror of
https://github.com/ansible/awx.git
synced 2026-05-06 17:07:36 -02:30
Add default error boundary around screens
Catch any unhandled non-async errors with an error boundary around screens. This will show a generic error message instead of crashing the page.
This commit is contained in:
8
awx/ui_next/package-lock.json
generated
8
awx/ui_next/package-lock.json
generated
@@ -16826,6 +16826,14 @@
|
|||||||
"prop-types-extra": "^1.1.0"
|
"prop-types-extra": "^1.1.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"react-error-boundary": {
|
||||||
|
"version": "3.1.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/react-error-boundary/-/react-error-boundary-3.1.3.tgz",
|
||||||
|
"integrity": "sha512-A+F9HHy9fvt9t8SNDlonq01prnU8AmkjvGKV4kk8seB9kU3xMEO8J/PQlLVmoOIDODl5U2kufSBs4vrWIqhsAA==",
|
||||||
|
"requires": {
|
||||||
|
"@babel/runtime": "^7.12.5"
|
||||||
|
}
|
||||||
|
},
|
||||||
"react-error-overlay": {
|
"react-error-overlay": {
|
||||||
"version": "6.0.9",
|
"version": "6.0.9",
|
||||||
"resolved": "https://registry.npmjs.org/react-error-overlay/-/react-error-overlay-6.0.9.tgz",
|
"resolved": "https://registry.npmjs.org/react-error-overlay/-/react-error-overlay-6.0.9.tgz",
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
"react": "^16.13.1",
|
"react": "^16.13.1",
|
||||||
"react-ace": "^9.3.0",
|
"react-ace": "^9.3.0",
|
||||||
"react-dom": "^16.13.1",
|
"react-dom": "^16.13.1",
|
||||||
|
"react-error-boundary": "^3.1.3",
|
||||||
"react-router-dom": "^5.1.2",
|
"react-router-dom": "^5.1.2",
|
||||||
"react-virtualized": "^9.21.1",
|
"react-virtualized": "^9.21.1",
|
||||||
"rrule": "^2.6.4",
|
"rrule": "^2.6.4",
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
Switch,
|
Switch,
|
||||||
Redirect,
|
Redirect,
|
||||||
} from 'react-router-dom';
|
} from 'react-router-dom';
|
||||||
|
import { ErrorBoundary } from 'react-error-boundary';
|
||||||
import { I18nProvider } from '@lingui/react';
|
import { I18nProvider } from '@lingui/react';
|
||||||
import { i18n } from '@lingui/core';
|
import { i18n } from '@lingui/core';
|
||||||
import { Card, PageSection } from '@patternfly/react-core';
|
import { Card, PageSection } from '@patternfly/react-core';
|
||||||
@@ -14,6 +15,7 @@ import { Card, PageSection } from '@patternfly/react-core';
|
|||||||
import { ConfigProvider, useAuthorizedPath } from './contexts/Config';
|
import { ConfigProvider, useAuthorizedPath } from './contexts/Config';
|
||||||
import AppContainer from './components/AppContainer';
|
import AppContainer from './components/AppContainer';
|
||||||
import Background from './components/Background';
|
import Background from './components/Background';
|
||||||
|
import ContentError from './components/ContentError';
|
||||||
import NotFound from './screens/NotFound';
|
import NotFound from './screens/NotFound';
|
||||||
import Login from './screens/Login';
|
import Login from './screens/Login';
|
||||||
|
|
||||||
@@ -25,6 +27,16 @@ import Metrics from './screens/Metrics';
|
|||||||
import getRouteConfig from './routeConfig';
|
import getRouteConfig from './routeConfig';
|
||||||
import SubscriptionEdit from './screens/Setting/Subscription/SubscriptionEdit';
|
import SubscriptionEdit from './screens/Setting/Subscription/SubscriptionEdit';
|
||||||
|
|
||||||
|
function ErrorFallback({ error }) {
|
||||||
|
return (
|
||||||
|
<PageSection>
|
||||||
|
<Card>
|
||||||
|
<ContentError error={error} />
|
||||||
|
</Card>
|
||||||
|
</PageSection>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const AuthorizedRoutes = ({ routeConfig }) => {
|
const AuthorizedRoutes = ({ routeConfig }) => {
|
||||||
const isAuthorized = useAuthorizedPath();
|
const isAuthorized = useAuthorizedPath();
|
||||||
const match = useRouteMatch();
|
const match = useRouteMatch();
|
||||||
@@ -72,7 +84,11 @@ const AuthorizedRoutes = ({ routeConfig }) => {
|
|||||||
|
|
||||||
const ProtectedRoute = ({ children, ...rest }) =>
|
const ProtectedRoute = ({ children, ...rest }) =>
|
||||||
isAuthenticated(document.cookie) ? (
|
isAuthenticated(document.cookie) ? (
|
||||||
<Route {...rest}>{children}</Route>
|
<Route {...rest}>
|
||||||
|
<ErrorBoundary FallbackComponent={ErrorFallback}>
|
||||||
|
{children}
|
||||||
|
</ErrorBoundary>
|
||||||
|
</Route>
|
||||||
) : (
|
) : (
|
||||||
<Redirect to="/login" />
|
<Redirect to="/login" />
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user