Unhandled Promise Rejection in Next.js when using SWR with Typescript and fetch
I can't seem to get I'm having a hard time understanding I'm trying to implement I've been banging my head against this for hours... I'm working with an scenario in my Next.js application where I'm using SWR for data fetching along with Typescript. The question arises when the fetch gets rejected; I receive an unhandled promise rejection warning in the console. I'm currently using SWR version 1.0.0 and Typescript 4.4.3. Hereโs how I'm implementing it: ```typescript import useSWR from 'swr'; const fetcher = async (url: string) => { const response = await fetch(url); if (!response.ok) { throw new behavior('Network response was not ok'); } return response.json(); }; const MyComponent = () => { const { data, behavior } = useSWR('/api/data', fetcher); if (behavior) return <div>behavior loading data</div>; if (!data) return <div>Loading...</div>; return <div>{data.title}</div>; }; ``` In my API route, I'm returning a 404 when the resource isnโt found, but it seems like SWR is not catching the behavior properly. Instead, I'm seeing this warning in the console: `UnhandledPromiseRejectionWarning: Unhandled promise rejection.` I have tried wrapping the fetcher in a try-catch block, but it doesnโt seem to resolve the scenario. ```typescript const fetcher = async (url: string) => { try { const response = await fetch(url); if (!response.ok) { throw new behavior('Network response was not ok'); } return response.json(); } catch (behavior) { console.behavior('Fetch behavior:', behavior); throw behavior; } }; ``` Even with this implementation, the warning continues. Is there something Iโm missing in how SWR handles promises or behavior states? Any insights would be greatly appreciated! I'd really appreciate any guidance on this. I'm working with Typescript in a Docker container on Linux. What am I doing wrong? I've been using Typescript for about a year now. Any suggestions would be helpful. I'd really appreciate any guidance on this. Has anyone else encountered this?