From 903ed571985cb01d2b550d122a9add801547e876 Mon Sep 17 00:00:00 2001 From: Morley Zhi Date: Thu, 20 Feb 2020 11:26:11 -0500 Subject: [PATCH] Make fetchTransactions more resilient to improper responses --- CHANGELOG.md | 5 +++++ package.json | 2 +- src/transfers/TransferProvider.ts | 11 +++++++++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aff4b91d..fed9ed34 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## In master + +- [Transfers] Make the transactions fetcher more resilient to invalid responses + from /transactions. + ## [v0.0.9-rc.1](https://github.com/stellar/js-stellar-wallets/compare/v0.0.8-rc.1...v0.0.9-rc.1) - [General] Add support for building a commonjs bundle diff --git a/package.json b/package.json index 75059ff2..742855fd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@stellar/wallet-sdk", - "version": "0.0.9-rc.1", + "version": "0.0.9-rc.2", "description": "Libraries to help you write Stellar-enabled wallets in Javascript", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/transfers/TransferProvider.ts b/src/transfers/TransferProvider.ts index 08a3e325..8d445ffe 100644 --- a/src/transfers/TransferProvider.ts +++ b/src/transfers/TransferProvider.ts @@ -175,9 +175,16 @@ export abstract class TransferProvider { }, ); - const { transactions } = await response.json(); + const text = await response.text(); - return transactions.map(_normalizeTransaction); + try { + const { transactions } = JSON.parse(text); + return transactions.map(_normalizeTransaction); + } catch (e) { + throw new Error( + `Invalid transaction response from ${this.transferServer}: ${text}`, + ); + } } /**