Skip to content

Commit

Permalink
Merge pull request #13 from LarveyOfficial/dev
Browse files Browse the repository at this point in the history
Better SWR Error Handling
  • Loading branch information
LarveyOfficial authored Apr 5, 2024
2 parents 7093c85 + 418b292 commit 19c8082
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ export default function Gif() {
// Check for new image every 1 second
const { data, error } = useSWR("/api/getConfig", fetcher, {
refreshInterval: 1000,
keepPreviousData: true,
onErrorRetry: (error, key, config, revalidate, { retryCount }) => {
// Never retry on 404.
if (error.status === 404) return;

// Only retry up to 5 times.
if (retryCount >= 5) return;

// Retry every second
setTimeout(() => revalidate({ retryCount }), 1000);
},
});

// Take user to panel when keybind detected
Expand Down

0 comments on commit 19c8082

Please sign in to comment.