From ff371f1d71a0a8af548f96d3271b183fbe8a7d1d Mon Sep 17 00:00:00 2001 From: Matthias Seghers Date: Sun, 3 Mar 2024 15:20:26 +0100 Subject: [PATCH] removed linting error in unkown type of error in error.tsx --- frontend/src/pages/error.tsx | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/frontend/src/pages/error.tsx b/frontend/src/pages/error.tsx index 353d6554..5d059a1e 100644 --- a/frontend/src/pages/error.tsx +++ b/frontend/src/pages/error.tsx @@ -1,4 +1,4 @@ -import { useRouteError } from "react-router-dom"; +import {isRouteErrorResponse, useRouteError} from "react-router-dom"; import {JSX} from 'react'; export default function ErrorPage(): JSX.Element { @@ -10,8 +10,29 @@ export default function ErrorPage(): JSX.Element {

Oops!

Sorry, an unexpected error has occurred.

- {error.statusText || error.message} + {errorMessage(error)}

); } + +interface RouterError extends Error {} + +function isRouterError(object: unknown): object is RouterError { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-expect-error + return 'message' in object; +} + +function errorMessage(error: unknown): string { + if (isRouteErrorResponse(error)) { + return `${error.status} ${error.statusText}` + } else if (error != undefined && isRouterError(error)) { + return error.message; + } else if (typeof error === 'string') { + return error + } else { + console.error(error) + return 'Unknown error' + } +} \ No newline at end of file