From 8fccb04ff8f8453e3ac89311c47a821d020c1b80 Mon Sep 17 00:00:00 2001 From: Zyuhel Date: Fri, 14 Jun 2019 17:26:25 +0300 Subject: [PATCH] add proper error handling for json response --- ops/get.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ops/get.js b/ops/get.js index c7aaab7..b0a1466 100644 --- a/ops/get.js +++ b/ops/get.js @@ -1,6 +1,7 @@ /* */ const config = require('../helpers/configReader.js') +const constants = require('../helpers/constants.js') const keys = require('../helpers/keys.js'); const passArgs = require('../helpers/passArgs.js') const popsicle = require('popsicle') @@ -65,14 +66,18 @@ module.exports=function (vorpal) { }).then(function (res) { var answer = JSON.parse(res.body) if (args.type=='message') { + if (answer.transaction.type !== constants.transactionTypes.CHAT_MESSAGE) { + if (callback) + callback() + return {success: false, error:"Not a message transaction"} + } if (answer.transaction.asset.chat.own_message) { var keypair = keys.createKeypairFromPassPhrase(passArgs.getPassPhrase(args)) var reader_address=keys.createAddressFromPublicKey(keypair.publicKey) if (reader_address!=answer.transaction.senderId && reader_address!=answer.transaction.recipientId) { - self.log("Can't decode message, key is not available"); if (callback) callback() - return false + return {success: false, error:"Can't decode message, key is not available"} } recipient_name=answer.transaction.senderId if (recipient_name===reader_address)