Download next.js/test/e2e/app-dir/app-static/lib/fetch-retry.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 395 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/test/e2e/app-dir/app-static/lib/fetch-retry.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/next.js/test/e2e/app-dir/app-static/lib/fetch-retry.js
-
curl -L -o fetch-retry.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/test/e2e/app-dir/app-static/lib/fetch-retry.js
395 Bytes
| import { unstable_rethrow } from 'next/navigation' | |
| const MAX_ATTEMPTS = 5 | |
| export const fetchRetry = async (url, init) => { | |
| for (let i = 0; i < MAX_ATTEMPTS; i++) { | |
| try { | |
| return await fetch(url, init) | |
| } catch (err) { | |
| unstable_rethrow(err) | |
| if (i === MAX_ATTEMPTS - 1) { | |
| throw err | |
| } | |
| console.log(`Failed to fetch`, err, `retrying...`) | |
| } | |
| } | |
| } | |