Skip to content

Commit

Permalink
add proper error handling for json response
Browse files Browse the repository at this point in the history
  • Loading branch information
zyuhel committed Jun 14, 2019
1 parent ae0fe39 commit 8fccb04
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions ops/get.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 8fccb04

Please sign in to comment.