feat(client): dynamic retry for "Client Retry Plugin"#318
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
WalkthroughThis pull request updates the retry mechanism in the ClientRetryPlugin. A new Changes
Sequence Diagram(s)sequenceDiagram
participant C as Client
participant P as ClientRetryPlugin
participant R as Retry Function
C->>P: Send request (with context, path, input)
P->>R: Evaluate retry(context, path, input)
R-->>P: Return retry count (2 for 'planet.list', 0 otherwise)
P->>C: Set maxAttempts & process request accordingly
Possibly related PRs
Poem
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov ReportAll modified and coverable lines are covered by tests ✅ 📢 Thoughts on this report? Let us know! |
More templates
@orpc/arktype
@orpc/client
@orpc/contract
@orpc/openapi
@orpc/openapi-client
@orpc/react
@orpc/react-query
@orpc/server
@orpc/shared
@orpc/solid-query
@orpc/standard-server
@orpc/standard-server-fetch
@orpc/standard-server-node
@orpc/svelte-query
@orpc/valibot
@orpc/vue-colada
@orpc/vue-query
@orpc/zod
commit: |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
apps/content/docs/plugins/client-retry.md (1)
28-36: Great implementation of dynamic retry behavior based on API path!This is a well-implemented example showing how to configure different retry behaviors for specific endpoints. The function checks if the path matches 'planet.list' and returns 2 retry attempts for that path, or 0 for all other paths.
Consider using constants for the retry counts and path values to improve maintainability:
default: { // Optional override for default options retry: (options, path) => { + const PLANET_LIST_PATH = 'planet.list'; + const PLANET_LIST_RETRIES = 2; + const DEFAULT_RETRIES = 0; - if (path.join('.') === 'planet.list') { - return 2 + if (path.join('.') === PLANET_LIST_PATH) { + return PLANET_LIST_RETRIES } - return 0 + return DEFAULT_RETRIES } },packages/client/src/plugins/retry.ts (1)
85-90: Correctly implemented dynamic retry value resolution!The implementation properly handles evaluating the retry value, whether it's a static number or a function. By using the
valuehelper, you ensure consistent behavior regardless of the retry value type.Consider adding error handling to prevent unexpected failures if the retry function throws an error:
const maxAttempts = await value( interceptorOptions.options.context.retry ?? this.defaultRetry, interceptorOptions.options, interceptorOptions.path, interceptorOptions.input, +).catch(err => { + console.error('Error determining retry count:', err); + return 0; // Default to no retries if there's an error });
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
apps/content/docs/plugins/client-retry.md(1 hunks)packages/client/src/plugins/retry.test.ts(1 hunks)packages/client/src/plugins/retry.ts(2 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
packages/client/src/plugins/retry.ts (2)
packages/client/src/types.ts (1)
ClientOptions(30-32)packages/client/src/adapters/standard/link.ts (1)
path(44-56)
🔇 Additional comments (2)
packages/client/src/plugins/retry.test.ts (1)
55-61: Good test implementation for the dynamic retry function!You've properly updated the test to validate the new dynamic retry behavior:
- Using a mock function instead of a static value
- Verifying the function is called exactly once with the correct parameters
This improves test coverage by ensuring not just that retries happen, but that the retry function is invoked with the expected arguments.
packages/client/src/plugins/retry.ts (1)
21-25: Well-designed type enhancement for dynamic retry behavior!The update to the
retryproperty's type signature properly expands its capabilities, allowing it to be:
- A static number (backward compatible)
- A function that can dynamically determine the retry count based on client options, path, and input
This design gives developers greater flexibility to implement contextual retry logic.
Summary by CodeRabbit