diff --git a/src/renderer/hooks/useGif.ts b/src/renderer/hooks/useGif.ts index 12fb0c9..b5dafb9 100644 --- a/src/renderer/hooks/useGif.ts +++ b/src/renderer/hooks/useGif.ts @@ -7,20 +7,24 @@ export default function useGif(url: string): TenorGif | null { const [gif, setGif] = useState(null); useEffect(() => { - const uri = new URL(url); + try { + const uri = new URL(url); - if (allowedHosts.includes(uri.host.toLowerCase())) { + if (allowedHosts.includes(uri.host.toLowerCase())) { + setGif(null); + return; + } + + window.electron.ipcRenderer + .invoke('tenor:fetch-gif', url) + .then((result: TenorFetchResult) => { + setGif(result.gif); + return true; + }) + .catch((err) => console.error(err)); + } catch { setGif(null); - return; } - - window.electron.ipcRenderer - .invoke('tenor:fetch-gif', url) - .then((result: TenorFetchResult) => { - setGif(result.gif); - return true; - }) - .catch((err) => console.error(err)); }, [url]); return gif;