diff --git a/www/app/(errors)/errorContext.tsx b/www/app/(errors)/errorContext.tsx index d8a80c04..d541c6f0 100644 --- a/www/app/(errors)/errorContext.tsx +++ b/www/app/(errors)/errorContext.tsx @@ -3,7 +3,8 @@ import React, { createContext, useContext, useState } from "react"; interface ErrorContextProps { error: Error | null; - setError: React.Dispatch>; + humanMessage?: string; + setError: (error: Error, humanMessage?: string) => void; } const ErrorContext = createContext(undefined); @@ -22,9 +23,16 @@ interface ErrorProviderProps { export const ErrorProvider: React.FC = ({ children }) => { const [error, setError] = useState(null); + const [humanMessage, setHumanMessage] = useState(); + const declareError = (error, humanMessage?) => { + setError(error); + setHumanMessage(humanMessage); + }; return ( - + {children} ); diff --git a/www/app/(errors)/errorMessage.tsx b/www/app/(errors)/errorMessage.tsx index 8b410c4c..6d198650 100644 --- a/www/app/(errors)/errorMessage.tsx +++ b/www/app/(errors)/errorMessage.tsx @@ -4,29 +4,51 @@ import { useEffect, useState } from "react"; import * as Sentry from "@sentry/react"; const ErrorMessage: React.FC = () => { - const { error, setError } = useError(); + const { error, setError, humanMessage } = useError(); const [isVisible, setIsVisible] = useState(false); + // Setup Shortcuts + useEffect(() => { + const handleKeyPress = (event: KeyboardEvent) => { + switch (event.key) { + case "^": + throw new Error("Unhandled Exception thrown by '^' shortcut"); + case "$": + setError( + new Error("Unhandled Exception thrown by '$' shortcut"), + "You did this to yourself", + ); + } + }; + + document.addEventListener("keydown", handleKeyPress); + return () => document.removeEventListener("keydown", handleKeyPress); + }, []); + useEffect(() => { if (error) { - setIsVisible(true); - Sentry.captureException(error); - console.error("Error", error.message, error); + if (humanMessage) { + setIsVisible(true); + Sentry.captureException(Error(humanMessage, { cause: error })); + } else { + Sentry.captureException(error); + } + + console.error("Error", error); } }, [error]); - if (!isVisible || !error) return null; + if (!isVisible || !humanMessage) return null; return ( ); }; diff --git a/www/app/[domain]/browse/pagination.tsx b/www/app/[domain]/browse/pagination.tsx index 27ff5f47..e10d5321 100644 --- a/www/app/[domain]/browse/pagination.tsx +++ b/www/app/[domain]/browse/pagination.tsx @@ -40,7 +40,7 @@ export default function Pagination(props: PaginationProps) { return (