From 17e84e7e2e8cf0a6f56483c11c8940710dccb169 Mon Sep 17 00:00:00 2001 From: Kushal7788 Date: Thu, 23 Jan 2025 17:17:10 +0530 Subject: [PATCH] Added support for Proof Retry --- src/Reclaim.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Reclaim.ts b/src/Reclaim.ts index 5ef34f0..ed69fd1 100644 --- a/src/Reclaim.ts +++ b/src/Reclaim.ts @@ -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) { @@ -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}`;