import React from "react"; import Box from "@mui/material/Box"; import Button from "@mui/material/Button"; import Card from "@mui/material/Card"; import CardActions from "@mui/material/CardActions"; import CardContent from "@mui/material/CardContent"; import { useTheme } from "@mui/material/styles"; import Typography from "@mui/material/Typography"; import { ApiLoadFailedError } from "../api"; import { useI18n } from "../contexts/I18nContext"; import { useUser } from "../contexts/UserContext"; import { PageLoadFailedError } from "./PageLoader"; const errorMessages: Record = { 403: "You are authenticated as %(username)s, but are not authorized to access this page. Would you like to login to a different account?", 404: "We're sorry, but the requested page could not be found.", }; interface ErrorScreenProps { error: PageLoadFailedError | ApiLoadFailedError | Error | string; } interface OnlineErrorScreenProps { error: PageLoadFailedError | Error; } interface GenericErrorScreenProps extends React.PropsWithChildren { header: string; description?: string; } const GenericErrorScreen: React.FC = ({ header, description, children, }) => { const theme = useTheme(); return ( {header} {description && {description}} {children && {children}} ); }; const ErrorScreen: React.FC = ({ error }) => { if (error instanceof ApiLoadFailedError) { return ( ); } if (error instanceof Error) { return ; } return ; }; const OnlineErrorScreen: React.FC = ({ error }) => { const { t } = useI18n(); const { user, logout } = useUser(); return ( = 500 ? "There's been an error. It's been reported to the site administrators via email and should be fixed shortly. Thanks for your patience." : errorMessages[error.response.status], user as unknown as Record, ) : undefined } header={`${error.name}: ${error.message}`} > {error instanceof PageLoadFailedError && error.response.status === 403 && ( )} ); }; export default ErrorScreen;