"use client"; import { useError } from "./errorContext"; import { useEffect, useState } from "react"; import * as Sentry from "@sentry/nextjs"; const ErrorMessage: React.FC = () => { 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) { if (humanMessage) { setIsVisible(true); Sentry.captureException(Error(humanMessage, { cause: error })); } else { Sentry.captureException(error); } console.error("Error", error); } }, [error]); if (!isVisible || !humanMessage) return null; return ( ); }; export default ErrorMessage;