-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathErrorBoundary.tsx
46 lines (43 loc) · 1.59 KB
/
ErrorBoundary.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import type { SerializedError } from '@reduxjs/toolkit';
import { useTranslation } from 'react-i18next';
import { Link, useNavigate, useRouteError } from 'react-router-dom';
import type { ApiError } from 'common/api/baseGeneratedApis';
import { ModalProvider } from 'common/BootstrapSNCF/ModalSNCF/ModalProvider';
import NavBarSNCF from 'common/BootstrapSNCF/NavBarSNCF';
import { getErrorMessage } from 'utils/error';
export default function ErrorBoundary() {
const error = useRouteError() as ApiError | SerializedError;
const { t } = useTranslation(['errors', 'common/common']);
const navigate = useNavigate();
return (
<ModalProvider>
<NavBarSNCF appName="OSRD" />
<main className="mastcontainer mastcontainer-no-mastnav d-flex align-items-center justify-content-center vh-100">
<div className="p-3">
{error ? (
<>
<h1>
{t(`errors:${(error as ApiError).status ? (error as ApiError).status : 'default'}`)}
</h1>
<p>{getErrorMessage(error)}</p>
</>
) : (
<h1>{t('errors:pageNotFound')}</h1>
)}
<Link to="/">
<button type="button" className="btn btn-primary btn-sm px-2">
{t('common/common:navigation.goHome')}
</button>
</Link>
<button
className="btn btn-primary btn-sm px-2 ml-2"
type="button"
onClick={() => navigate(-1)}
>
{t('common/common:navigation.goBack')}
</button>
</div>
</main>
</ModalProvider>
);
}