securityos/hooks/useGlobalErrorHandler.ts

19 lines
513 B
TypeScript
Raw Permalink Normal View History

2024-09-06 15:32:35 +00:00
import { useEffect } from "react";
import { haltEvent } from "utils/functions";
const useGlobalErrorHandler = (): void => {
useEffect(() => {
const errorHandler = (event: Event & { error: Error }): void => {
if (event.error?.stack?.includes("eval at <anonymous>")) {
haltEvent(event);
}
};
window.addEventListener("error", errorHandler);
return () => window.removeEventListener("error", errorHandler);
}, []);
};
export default useGlobalErrorHandler;