Add retry for fetching paymentInformation#4259
Conversation
📝 WalkthroughWalkthroughThis pull request adds retry logic with exponential backoff to the payment information query in ChangesPayment Query Retry Configuration
🎯 2 (Simple) | ⏱️ ~8 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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.
🧹 Nitpick comments (1)
src/features/payment/PaymentInformationProvider.tsx (1)
34-49: ⚡ Quick winUse
queryOptions+ object-managed query key for both payment query branches.Both branches still return raw option objects directly. To match repo guidance and keep retry/query config centrally composable, wrap these definitions with TanStack
queryOptionsand use object segments in query keys consistently.♻️ Suggested refactor
+import { queryOptions, skipToken, useQuery } from '`@tanstack/react-query`'; ... if (appSupportsPaymentWebhooks(altinnNugetVersion)) { - return { - queryKey: ['fetchPaymentInfoForTask', instanceId, selectedLanguage], + return queryOptions({ + queryKey: ['fetchPaymentInfoForTask', { instanceId, selectedLanguage, taskId }] as const, queryFn: instanceId ? () => fetchPaymentInformationForTask(instanceId, selectedLanguage, taskId) : skipToken, enabled: enabled && !!instanceId, retry: 3, retryDelay: (attemptIndex) => Math.min(1000 * 2 ** attemptIndex, 30000), - }; + }); } else { - return { - queryKey: ['fetchPaymentInfo'], + return queryOptions({ + queryKey: ['fetchPaymentInfo', { instanceId, selectedLanguage }] as const, queryFn: instanceId ? () => fetchPaymentInformation(instanceId, selectedLanguage) : skipToken, enabled: enabled && !!instanceId, gcTime: 0, retry: 3, retryDelay: (attemptIndex) => Math.min(1000 * 2 ** attemptIndex, 30000), - }; + }); }As per coding guidelines, "Use objects for managing query keys and functions with
queryOptionsfor sharing TanStack Query configuration across the system for central management".🤖 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 `@src/features/payment/PaymentInformationProvider.tsx` around lines 34 - 49, Replace the raw option objects returned in PaymentInformationProvider with TanStack queryOptions and use object-based query keys: build an object key (e.g., { scope: 'fetchPaymentInfoForTask', instanceId, selectedLanguage, taskId } or { scope: 'fetchPaymentInfo', instanceId, selectedLanguage }) and return queryOptions({ queryKey: thatObject, queryFn: instanceId ? () => fetchPaymentInformationForTask(instanceId, selectedLanguage, taskId) : skipToken, enabled: enabled && !!instanceId, retry: 3, retryDelay: (attemptIndex) => Math.min(1000 * 2 ** attemptIndex, 30000) }) for the task branch and similarly use queryOptions with the fetchPaymentInformation queryFn for the other branch (preserve gcTime: 0 on the non-task branch inside queryOptions).Source: Coding guidelines
🤖 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.
Nitpick comments:
In `@src/features/payment/PaymentInformationProvider.tsx`:
- Around line 34-49: Replace the raw option objects returned in
PaymentInformationProvider with TanStack queryOptions and use object-based query
keys: build an object key (e.g., { scope: 'fetchPaymentInfoForTask', instanceId,
selectedLanguage, taskId } or { scope: 'fetchPaymentInfo', instanceId,
selectedLanguage }) and return queryOptions({ queryKey: thatObject, queryFn:
instanceId ? () => fetchPaymentInformationForTask(instanceId, selectedLanguage,
taskId) : skipToken, enabled: enabled && !!instanceId, retry: 3, retryDelay:
(attemptIndex) => Math.min(1000 * 2 ** attemptIndex, 30000) }) for the task
branch and similarly use queryOptions with the fetchPaymentInformation queryFn
for the other branch (preserve gcTime: 0 on the non-task branch inside
queryOptions).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: e14916df-b0a0-4fc9-9834-e81ca6b5f486
📒 Files selected for processing (1)
src/features/payment/PaymentInformationProvider.tsx
|
✅ Automatic backport successful! A backport PR has been automatically created for the The release branch The cherry-pick was clean with no conflicts. Please review the backport PR when it appears. |



Description
Adds retry with exponential backoff to the payment information query (
GET …/payment), mirroring the existing instance-data query policy (retry: 3).Returning from the hosted payment page races with the payment webhook that advances the process. In that window the endpoint can briefly fail (a momentarily locked data element, or a transient 5xx/network blip). With no retry, a single bad response immediately rendered the
DisplayErrorpage and stranded the user after a completed payment. Retrying a few times lets the backend settle before any error surfaces.Related Issue(s)
Verification/QA
kind/*andbackport*label to this PR for proper release notes groupingSummary by CodeRabbit