Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/soft-schools-bake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/clerk-js': patch
---

Retry confrim checkout requests if any erros with >=500 status code occur
30 changes: 24 additions & 6 deletions packages/clerk-js/src/core/resources/CommerceCheckout.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { retry } from '@clerk/shared/retry';
import type {
__experimental_CommerceCheckoutJSON,
__experimental_CommerceCheckoutResource,
Expand Down Expand Up @@ -55,11 +56,28 @@ export class __experimental_CommerceCheckout extends BaseResource implements __e

confirm = (params: __experimental_ConfirmCheckoutParams): Promise<this> => {
const { orgId, ...rest } = params;
return this._basePatch({
path: orgId
? `/organizations/${orgId}/commerce/checkouts/${this.id}/confirm`
: `/me/commerce/checkouts/${this.id}/confirm`,
body: rest as any,
});

// Retry confirmation in case of a 500 error
// This will retry up to 3 times with an increasing delay
// It retries at 2s, 4s, 6s and 8s
return retry(
() =>
this._basePatch({
path: orgId
? `/organizations/${orgId}/commerce/checkouts/${this.id}/confirm`
: `/me/commerce/checkouts/${this.id}/confirm`,
body: rest as any,
}),
{
factor: 1.1,
maxDelayBetweenRetries: 2 * 1_000,
initialDelay: 2 * 1_000,
jitter: false,
shouldRetry(error: any, iterations: number) {
const status = error?.status;
return !!status && status >= 500 && iterations <= 4;
},
},
);
};
}