Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Commit

Permalink
removed linting error in unkown type of error in error.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
matt01y committed Mar 3, 2024
1 parent 629bf15 commit ff371f1
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions frontend/src/pages/error.tsx
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -10,8 +10,29 @@ export default function ErrorPage(): JSX.Element {
<h1>Oops!</h1>
<p>Sorry, an unexpected error has occurred.</p>
<p>
<i>{error.statusText || error.message}</i>
<i>{errorMessage(error)}</i>
</p>
</div>
);
}

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'
}
}

0 comments on commit ff371f1

Please sign in to comment.