Spaces:
Paused
Paused
Download src/hooks/useGlobalFetchError.ts from GraziePrego/deepresearch: direct link, hf CLI and curl.
- Browser
- Download file 758 Bytes
-
https://huggingface.co/spaces/GraziePrego/deepresearch/resolve/main/src/hooks/useGlobalFetchError.ts
- Command line
-
hf download hf://spaces/GraziePrego/deepresearch/src/hooks/useGlobalFetchError.ts
-
curl -L -o useGlobalFetchError.ts https://huggingface.co/spaces/GraziePrego/deepresearch/resolve/main/src/hooks/useGlobalFetchError.ts
758 Bytes
| import { useEffect } from "react"; | |
| import { toast } from "sonner"; | |
| export function useGlobalFetchError() { | |
| useEffect(() => { | |
| const handleError = (event: PromiseRejectionEvent) => { | |
| if (event.reason instanceof TypeError && event.reason.message === "Failed to fetch") { | |
| console.error("Global Fetch Error detected:", event.reason); | |
| toast.error("Network connection issue. Please check your connection or refresh the page.", { | |
| description: "This can happen if the server is sleeping or your network is unstable.", | |
| duration: 5000, | |
| }); | |
| } | |
| }; | |
| window.addEventListener("unhandledrejection", handleError); | |
| return () => window.removeEventListener("unhandledrejection", handleError); | |
| }, []); | |
| } | |