Skip to content

Commit

Permalink
updated error handling from sendTransaction
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffWScott committed Mar 1, 2021
1 parent 091be55 commit 39f2995
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
10 changes: 7 additions & 3 deletions dist/lamden.js
Original file line number Diff line number Diff line change
Expand Up @@ -5681,7 +5681,11 @@ class LamdenMasterNode_API{

return fetch(`${overrideURL ? overrideURL : this.url}${path}${parms}`, options)
.then(res => {
return res.json()
if (res.status === 200){
return res.json()
}else{
return callback(undefined, res.statusText)
}
} )
.then(json => {
return callback(json, undefined)
Expand Down Expand Up @@ -6089,8 +6093,8 @@ class TransactionBuilder extends Network {
if (!masternodeURL && this.nonceMasternode) masternodeURL = this.nonceMasternode;
let response = await this.API.sendTransaction(this.tx, masternodeURL);
//Set error if txSendResult doesn't exist
if (response === 'undefined' || validateTypes$3.isStringWithValue(response)){
this.txSendResult.errors = ['TypeError: Failed to fetch'];
if (typeof response === 'undefined' || validateTypes$3.isStringWithValue(response)){
this.txSendResult.errors = [response || 'TypeError: Failed to fetch'];
}else{
if (response.error) this.txSendResult.errors = [response.error];
else this.txSendResult = response;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lamden-js",
"version": "1.4.9",
"version": "1.5.1",
"description": "A javascript implementaion for creating wallets, submitting transactions and interacting with masternodes on the Lamden Blockchain.",
"main": "dist/lamden.js",
"scripts": {
Expand Down
6 changes: 5 additions & 1 deletion src/js/masternode-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ export class LamdenMasterNode_API{

return fetch(`${overrideURL ? overrideURL : this.url}${path}${parms}`, options)
.then(res => {
return res.json()
if (res.status === 200){
return res.json()
}else{
return callback(undefined, res.statusText)
}
} )
.then(json => {
return callback(json, undefined)
Expand Down
4 changes: 2 additions & 2 deletions src/js/transactionBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ export class TransactionBuilder extends Network {
if (!masternodeURL && this.nonceMasternode) masternodeURL = this.nonceMasternode
let response = await this.API.sendTransaction(this.tx, masternodeURL)
//Set error if txSendResult doesn't exist
if (response === 'undefined' || validateTypes.isStringWithValue(response)){
this.txSendResult.errors = ['TypeError: Failed to fetch']
if (typeof response === 'undefined' || validateTypes.isStringWithValue(response)){
this.txSendResult.errors = [response || 'TypeError: Failed to fetch']
}else{
if (response.error) this.txSendResult.errors = [response.error]
else this.txSendResult = response
Expand Down
3 changes: 2 additions & 1 deletion test/transactionBuilder-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ describe('Test TransactionBuilder class', () => {
it('throws error if provided network is unresponsive', async function () {
let newTx = new Lamden.TransactionBuilder(badNetwork, txInfo_withNonce)
let response = await newTx.send(senderWallet.sk)
expect(response.errors[0].includes('Failed to fetch')).to.be(true)
expect(response.errors[0])
.to.be('FetchError: request to http://badnetwork.lamden.io:18080/ failed, reason: getaddrinfo ENOTFOUND badnetwork.lamden.io')

})
it('can return execution errors list', async function () {
Expand Down

0 comments on commit 39f2995

Please sign in to comment.