diff --git a/src/components/ErrorPage.tsx b/src/components/ErrorPage.tsx index a95643de2..0705074be 100644 --- a/src/components/ErrorPage.tsx +++ b/src/components/ErrorPage.tsx @@ -8,9 +8,32 @@ import { faTrash, } from '@fortawesome/free-solid-svg-icons' +/** Type narrowing function of unknown error to a string */ +function errorMessage(error: unknown): string { + if (isRouteErrorResponse(error)) { + return `${error.status} ${error.statusText}` + } else if (error != undefined && error instanceof Error) { + return error.message + } else if (error && typeof error === 'object') { + return JSON.stringify(error) + } else if (typeof error === 'string') { + return error + } else { + return 'Unknown error' + } +} + +/** Generate a GitHub issue URL from the error */ +function generateToUrl(error: unknown) { + const title: string = 'An unexpected error occurred' + const body = errorMessage(error) + const result = `https://github.com/KittyCAD/modeling-app/issues/new?title=${title}&body=${body}` + return result +} + export const ErrorPage = () => { let error = useRouteError() - + // We log the error to the console no matter what console.error('error', error) return ( @@ -19,11 +42,9 @@ export const ErrorPage = () => {

An unexpected error occurred

- {isRouteErrorResponse(error) && ( -

- {error.status}: {error.data} -

- )} +

+ <>{errorMessage(error)} +

{isDesktop() && ( { Report Bug