fix json-rpc issue
This commit is contained in:
parent
0c893f5b22
commit
dcef083d49
2 changed files with 17 additions and 15 deletions
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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, ''))
|
||||
]))
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue