Keycloak
1import {
2Button,
3Modal,
4ModalVariant,
5Page,
6Text,
7TextContent,
8TextVariants,
9} from "@patternfly/react-core";
10import { useTranslation } from "react-i18next";
11import { isRouteErrorResponse, useRouteError } from "react-router-dom";
12
13export const ErrorPage = () => {
14const { t } = useTranslation();
15const error = useRouteError();
16const errorMessage = getErrorMessage(error);
17
18function onRetry() {
19location.href = location.origin + location.pathname;
20}
21
22return (
23<Page>
24<Modal
25variant={ModalVariant.small}
26title={t("somethingWentWrong")}
27titleIconVariant="danger"
28showClose={false}
29isOpen
30actions={[
31<Button key="tryAgain" variant="primary" onClick={onRetry}>
32{t("tryAgain")}
33</Button>,
34]}
35>
36<TextContent>
37<Text>{t("somethingWentWrongDescription")}</Text>
38{errorMessage && (
39<Text component={TextVariants.small}>{errorMessage}</Text>
40)}
41</TextContent>
42</Modal>
43</Page>
44);
45};
46
47function getErrorMessage(error: unknown): string | null {
48if (typeof error === "string") {
49return error;
50}
51
52if (isRouteErrorResponse(error)) {
53return error.statusText;
54}
55
56if (error instanceof Error) {
57return error.message;
58}
59
60return null;
61}
62