From dcef083d4944bbf3bce8c99a7e8fe0ad2fd99cec Mon Sep 17 00:00:00 2001 From: Josh Harvey Date: Mon, 16 Jul 2018 17:00:09 +0300 Subject: [PATCH] fix json-rpc issue --- dev/json-rpc.js | 20 ++++++++++---------- lib/plugins/common/json-rpc.js | 12 +++++++----- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/dev/json-rpc.js b/dev/json-rpc.js index c5fcb028..01f49cdd 100644 --- a/dev/json-rpc.js +++ b/dev/json-rpc.js @@ -1,19 +1,19 @@ const rpc = require('../lib/plugins/common/json-rpc') +const method = '' + +// const url = null +// const url = 'https://httpstat.us/500' +// const url = 'https://httpstat.us/400' +const url = 'https://httpstat.us/200' + const account = { username: 'test', password: 'test', - port: 8080 + port: 8080, + url } -const method = {} - -const params = { - // url: 'https://httpstat.us/500' - // url: 'https://httpstat.us/400' - // url: 'https://httpstat.us/200' -} - -rpc.fetch(account, method, params) +rpc.fetch(account, method) .then(res => console.log('got result', res)) .catch(err => console.error('gor error', err)) diff --git a/lib/plugins/common/json-rpc.js b/lib/plugins/common/json-rpc.js index fc6b3a14..03cad38f 100644 --- a/lib/plugins/common/json-rpc.js +++ b/lib/plugins/common/json-rpc.js @@ -6,7 +6,9 @@ const _ = require('lodash/fp') module.exports = {fetch, parseConf} -function fetch (account = {}, method = {}, params = {}) { +function fetch (account = {}, method, params) { + params = _.defaultTo([], params) + return Promise.resolve(true) .then(() => { const data = { @@ -16,8 +18,8 @@ function fetch (account = {}, method = {}, params = {}) { } if (_.isNil(account.port)) throw new Error('port attribute required for jsonRpc') - - const url = _.defaultTo(`http://localhost:${account.port}`, params.url) + + const url = _.defaultTo(`http://localhost:${account.port}`, account.url) return axios({ method: 'post', @@ -33,8 +35,8 @@ function fetch (account = {}, method = {}, params = {}) { .catch(err => { throw new Error(_.join(' ', [ 'json-rpc::axios error:', - _.get('message', err, ''), - _.get('response.data.error', err, '') + JSON.stringify(_.get('message', err, '')), + JSON.stringify(_.get('response.data.error', err, '')) ])) }) }