()
| 48 | setAttempt(0); |
| 49 | |
| 50 | const run = async () => { |
| 51 | let delay = INITIAL_DELAY_MS; |
| 52 | let currentAttempt = 0; |
| 53 | |
| 54 | while (!cancelledRef.current) { |
| 55 | currentAttempt++; |
| 56 | setAttempt(currentAttempt); |
| 57 | |
| 58 | if (Date.now() - startedAt >= MAX_TOTAL_MS) { |
| 59 | setError({ |
| 60 | statusCode: 408, |
| 61 | errorCode: 'CLAIM_POLL_TIMEOUT', |
| 62 | message: 'Timed out waiting for the activation code to be issued.', |
| 63 | }); |
| 64 | setStatus('error'); |
| 65 | return; |
| 66 | } |
| 67 | |
| 68 | const result = await claimActivationCode(sessionId); |
| 69 | if (cancelledRef.current) { |
| 70 | return; |
| 71 | } |
| 72 | |
| 73 | if (!isServiceError(result)) { |
| 74 | setActivationCode(result.activationCode); |
| 75 | setStatus('success'); |
| 76 | return; |
| 77 | } |
| 78 | |
| 79 | if (result.errorCode !== ACTIVATION_CODE_NOT_READY) { |
| 80 | setError(result); |
| 81 | setStatus('error'); |
| 82 | return; |
| 83 | } |
| 84 | |
| 85 | await new Promise((resolve) => setTimeout(resolve, delay)); |
| 86 | delay = Math.min(delay * 2, MAX_DELAY_MS); |
| 87 | } |
| 88 | }; |
| 89 | |
| 90 | void run(); |
| 91 | }, []); |
no test coverage detected