Skip to content

Commit

Permalink
fix: Improve error handling in TonApi service
Browse files Browse the repository at this point in the history
  • Loading branch information
Ho3einWave committed Oct 27, 2024
1 parent 9630eae commit 099bd30
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/services/tonapi/tonapi.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,20 @@ export class TonApi extends Services {
await new Promise((resolve) => setTimeout(resolve, period_ms));
result = await this.client.tonapi.getTransactionEvent(hash);
retries++;
if (retries > maxRetry) {
throw new Error('Max retries reached');
}
}
return result;
} catch (error) {
await new Promise((resolve) => setTimeout(resolve, period_ms));
retries++;
if (retries > maxRetry) {
throw new Error('Max retries reached');
}
}
}
throw new Error('Max retries reached');
}

/**
Expand All @@ -149,7 +156,8 @@ export class TonApi extends Services {
*/
public allTransactionComplete(event: TransactionEvent) {
if (event.in_progress) return false;
if (event.actions.some((item) => item.status !== 'ok')) return false;
if (event.actions.some((item) => item.status !== 'ok'))
throw new Error('Transaction failed');
return true;
}
}

0 comments on commit 099bd30

Please sign in to comment.