Skip to content
This repository has been archived by the owner on Feb 8, 2024. It is now read-only.

Commit

Permalink
Throw more instructive errors when transfer responses aren't JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
Morley Zhi committed Jan 8, 2020
1 parent a1ac23a commit 70dad67
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stellar/wallet-sdk",
"version": "0.0.8-rc.5",
"version": "0.0.8-rc.6",
"description": "Libraries to help you write Stellar-enabled wallets in Javascript",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
10 changes: 9 additions & 1 deletion src/transfers/DepositProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,15 @@ export class DepositProvider extends TransferProvider {
const response = await fetch(`${this.transferServer}/deposit?${qs}`, {
headers: isAuthRequired ? this.getHeaders() : undefined,
});
const json = (await response.json()) as TransferResponse;

const text = await response.text();
let json;

try {
json = JSON.parse(text) as TransferResponse;
} catch (e) {
throw new Error(`Error parsing the deposit response as JSON: ${text}`);
}

if (json.error) {
const error: TransferError = new Error(
Expand Down
10 changes: 9 additions & 1 deletion src/transfers/WithdrawProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,15 @@ export class WithdrawProvider extends TransferProvider {
const response = await fetch(`${this.transferServer}/withdraw?${qs}`, {
headers: isAuthRequired ? this.getHeaders() : undefined,
});
const json = (await response.json()) as TransferResponse;

const text = await response.text();
let json;

try {
json = JSON.parse(text) as TransferResponse;
} catch (e) {
throw new Error(`Error parsing the deposit response as JSON: ${text}`);
}

if (json.error) {
const error: TransferError = new Error(json.error);
Expand Down

0 comments on commit 70dad67

Please sign in to comment.