正在显示
1 个修改的文件
包含
12 行增加
和
3 行删除
... | ... | @@ -4,12 +4,21 @@ var http = require("http"); |
4 | 4 | var uuid = require('uuid/v4'); |
5 | 5 | var URL = require('url'); |
6 | 6 | exports = module.exports = function (logger, settings) { |
7 | + | |
8 | + | |
9 | + function addParams(params) { | |
10 | + var postData = !params ? '' : JSON.stringify(params || {}); | |
11 | + return postData; | |
12 | + } | |
13 | + | |
14 | + | |
7 | 15 | /* |
8 | 16 | * var options={ |
9 | 17 | 'host': 'xxx.xxx.xxx.xxx', |
10 | 18 | 'port': 'xxxxx', |
11 | 19 | 'path': '/uaa/v1/xxxxx', |
12 | 20 | 'method': 'POST', |
21 | + 'params':{}, | |
13 | 22 | 'agent': false, |
14 | 23 | 'headers': { |
15 | 24 | "Accept": "application/json", |
... | ... | @@ -20,9 +29,9 @@ exports = module.exports = function (logger, settings) { |
20 | 29 | } |
21 | 30 | */ |
22 | 31 | |
23 | - var client = function (options, success, fail) { | |
32 | + var client = function (options) { | |
24 | 33 | return new Promise(function (resolve, reject) { |
25 | - var postData = !options.params ? '' : options.params; | |
34 | + var postData = addParams(options.params); | |
26 | 35 | var httpRequest = http.request(options, function (res) { |
27 | 36 | var _data = ''; |
28 | 37 | res.setEncoding('utf8'); |
... | ... | @@ -34,7 +43,7 @@ exports = module.exports = function (logger, settings) { |
34 | 43 | }); |
35 | 44 | }); |
36 | 45 | httpRequest.on('error', function (e) { |
37 | - reject(e); | |
46 | + reject(_data, e); | |
38 | 47 | }); |
39 | 48 | httpRequest.write(postData); |
40 | 49 | httpRequest.end(); | ... | ... |
请
注册
或
登录
后发表评论