Skip to content

Commit

Permalink
fix(android): adds timeout for createInvoice if 403 error occurs
Browse files Browse the repository at this point in the history
  • Loading branch information
cmgustavo committed Apr 16, 2020
1 parent b0feac9 commit 2607ef4
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/providers/gift-card/gift-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ export class GiftCardProvider extends InvoiceProvider {
return user && userSettings && userSettings.syncGiftCardPurchases;
}

public async createBitpayInvoice(data) {
public async createBitpayInvoice(data, attempt: number = 1) {
this.logger.info('BitPay Creating Invoice: try... ' + attempt);
const params = {
brand: data.cardName,
currency: data.currency,
Expand All @@ -142,11 +143,16 @@ export class GiftCardProvider extends InvoiceProvider {
};
const shouldSync = await this.shouldSyncGiftCardPurchasesWithBitPayId();
const promise = shouldSync
? this.createAuthenticatedBitpayInvoice(params)
: this.createUnauthenticatedBitpayInvoice(params);
const cardOrder = await promise.catch(err => {
this.logger.error('BitPay Create Invoice: ERROR', JSON.stringify(data));
throw err;
? this.createAuthenticatedBitpayInvoice.bind(this)
: this.createUnauthenticatedBitpayInvoice.bind(this);

const cardOrder = await promise(params).catch(async err => {
this.logger.error('BitPay Create Invoice: ERROR', JSON.stringify(err));
if (attempt <= 3 && err.status == 403) {
attempt++;
await new Promise(resolve => setTimeout(resolve, 3000));
return this.createBitpayInvoice(data, attempt);
} else throw err;
});
this.logger.info('BitPay Create Invoice: SUCCESS');
return cardOrder as {
Expand Down

0 comments on commit 2607ef4

Please sign in to comment.