Skip to content

Commit

Permalink
fix: fix stx balance command crash if address not valid
Browse files Browse the repository at this point in the history
  • Loading branch information
ahsan-javaid authored and reedrosenbluth committed Jun 28, 2021
1 parent 4ce29cb commit 8cc69df
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,15 @@ function balance(network: CLINetworkAdapter, args: string[]): Promise<string> {
txNetwork.coreApiUrl = network.legacyNetwork.blockstackAPIUrl;

return fetch(txNetwork.getAccountApiUrl(address))
.then(response => response.json())
.then(response => {
if (response.status === 404) {
return Promise.reject({
status: response.status,
error: response.statusText,
});
}
return response.json();
})
.then(response => {
let balanceHex = response.balance;
if (response.balance.startsWith('0x')) {
Expand All @@ -390,7 +398,8 @@ function balance(network: CLINetworkAdapter, args: string[]): Promise<string> {
nonce: response.nonce,
};
return Promise.resolve(JSONStringify(res));
});
})
.catch(error => error);
}

/*
Expand Down

1 comment on commit 8cc69df

@vercel
Copy link

@vercel vercel bot commented on 8cc69df Jun 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.