Skip to content
This repository was archived by the owner on Oct 8, 2019. It is now read-only.

Commit 9cd5273

Browse files
committed
Add error handling
1 parent 670b732 commit 9cd5273

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

index.js

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -150,29 +150,35 @@ function postTransaction(container, transaction, cb){
150150
};
151151

152152
let senderAddress = arkjs.crypto.getAddress(transaction.senderPublicKey);
153-
getFromNode('http://' + server + '/api/accounts?address=' + senderAddress, function(err, response, body){
154-
if(body) {
155-
body = JSON.parse(body);
156-
if (body.account.secondSignature) {
157-
container.prompt({
158-
type: 'password',
159-
name: 'passphrase',
160-
message: 'Second passphrase: ',
161-
}, function(result) {
162-
if (result.passphrase) {
163-
var secondKeys = arkjs.crypto.getKeys(result.passphrase);
164-
arkjs.crypto.secondSign(transaction, secondKeys);
165-
transaction.id = arkjs.crypto.getId(transaction);
153+
getFromNode('http://' + server + '/api/accounts?address=' + senderAddress,
154+
function(err, response, body){
155+
// handle the potential error
156+
if(err) {
157+
vorpal.log('Someting went wrong: '+err);
158+
159+
} else {
160+
if(body) {
161+
body = JSON.parse(body);
162+
if (body.account.secondSignature) {
163+
container.prompt({
164+
type: 'password',
165+
name: 'passphrase',
166+
message: 'Second passphrase: ',
167+
}, function(result) {
168+
if (result.passphrase) {
169+
var secondKeys = arkjs.crypto.getKeys(result.passphrase);
170+
arkjs.crypto.secondSign(transaction, secondKeys);
171+
transaction.id = arkjs.crypto.getId(transaction);
166172

167-
} else {
168-
vorpal.log('No second passphrase given. Trying without.');
173+
} else {
174+
vorpal.log('No second passphrase given. Trying without.');
169175

170-
}
171-
});
172-
173-
}
174-
performPost();
175-
}
176+
}
177+
});
178+
}
179+
performPost();
180+
} // if(body)
181+
} // if(err)
176182
});
177183
}
178184

0 commit comments

Comments
 (0)