docs: document function form of retryDelay#593
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis PR updates README.md to document that ChangesDocumentation
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@README.md`:
- Around line 134-142: The retryDelay example uses
Number(context.response?.headers.get("retry-after")) which treats null as 0;
change retryDelay to first read the header into a variable (e.g.,
retryAfterHeader = context.response?.headers.get("retry-after")), then only
convert it to a number if the header is non-null (or use parseInt and check
!isNaN), and finally use Number.isFinite(retryAfter) to decide between
retryAfter * 1000 and the 500ms fallback; update the example around ofetch's
retryDelay/context.response?.headers.get to implement this null-check before
numeric conversion.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
| ```ts | ||
| await ofetch("/api", { | ||
| retry: 3, | ||
| retryDelay: (context) => { | ||
| const retryAfter = Number(context.response?.headers.get("retry-after")); | ||
| return Number.isFinite(retryAfter) ? retryAfter * 1000 : 500; | ||
| }, | ||
| }); | ||
| ``` |
There was a problem hiding this comment.
Fix the null-handling edge case in the example.
When the Retry-After header is absent, headers.get("retry-after") returns null. Since Number(null) evaluates to 0 (which is finite), the current example returns a 0ms delay instead of the intended 500ms fallback.
🛡️ Proposed fix to handle missing header correctly
retryDelay: (context) => {
- const retryAfter = Number(context.response?.headers.get("retry-after"));
- return Number.isFinite(retryAfter) ? retryAfter * 1000 : 500;
+ const retryAfterHeader = context.response?.headers.get("retry-after");
+ const retryAfter = retryAfterHeader ? Number(retryAfterHeader) : NaN;
+ return Number.isFinite(retryAfter) && retryAfter > 0 ? retryAfter * 1000 : 500;
},🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@README.md` around lines 134 - 142, The retryDelay example uses
Number(context.response?.headers.get("retry-after")) which treats null as 0;
change retryDelay to first read the header into a variable (e.g.,
retryAfterHeader = context.response?.headers.get("retry-after")), then only
convert it to a number if the header is non-null (or use parseInt and check
!isNaN), and finally use Number.isFinite(retryAfter) to decide between
retryAfter * 1000 and the 500ms fallback; update the example around ofetch's
retryDelay/context.response?.headers.get to implement this null-check before
numeric conversion.
The function form retryDelay(context) => number has been supported since unjs#372 but the Auto Retry section only documents the numeric form. Adds a note and a Retry-After example. Docs-only.
3d9f00e to
cef9355
Compare
retryDelaycan be a function(context: FetchContext) => number, supported since #372, but the Auto Retry section of the README only documents the numeric form.This PR adds a short note that
retryDelaycan be a function receiving the fetch context, plus an example that honors a server'sRetry-Afterresponse header.Docs-only; no code changes.
Summary by CodeRabbit