Skip to content

Commit

Permalink
Merge pull request #22 from reclaimprotocol/proof-retry-functionality
Browse files Browse the repository at this point in the history
Added support for Proof Retry
  • Loading branch information
Kushal7788 authored Jan 23, 2025
2 parents 8659ffc + 17e84e7 commit bf48263
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/Reclaim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ export class ReclaimProofRequest {
private timeStamp: string;
private sdkVersion: string;
private jsonProofResponse: boolean = false;
private lastFailureTime?: number;
private readonly FAILURE_TIMEOUT = 30000; // 30 seconds timeout, can be adjusted

// Private constructor
private constructor(applicationId: string, providerId: string, options?: ProofRequestOptions) {
Expand Down Expand Up @@ -497,8 +499,21 @@ export class ReclaimProofRequest {
const statusUrlResponse = await fetchStatusUrl(this.sessionId);

if (!statusUrlResponse.session) return;

// Reset failure time if status is not PROOF_GENERATION_FAILED
if (statusUrlResponse.session.statusV2 !== SessionStatus.PROOF_GENERATION_FAILED) {
this.lastFailureTime = undefined;
}

// Check for failure timeout
if (statusUrlResponse.session.statusV2 === SessionStatus.PROOF_GENERATION_FAILED) {
throw new ProviderFailedError();
const currentTime = Date.now();
if (!this.lastFailureTime) {
this.lastFailureTime = currentTime;
} else if (currentTime - this.lastFailureTime >= this.FAILURE_TIMEOUT) {
throw new ProviderFailedError('Proof generation failed - timeout reached');
}
return; // Continue monitoring if under timeout
}

const isDefaultCallbackUrl = this.getAppCallbackUrl() === `${constants.DEFAULT_RECLAIM_CALLBACK_URL}${this.sessionId}`;
Expand Down

0 comments on commit bf48263

Please sign in to comment.