...
|
...
|
@@ -10,6 +10,7 @@ const rp = require('request-promise'); |
|
|
const _ = require('lodash');
|
|
|
const log = require('./logger');
|
|
|
const api = require('../config/common').domains.api;
|
|
|
const Timer = require('./timer');
|
|
|
|
|
|
const ApiUrl = api;
|
|
|
|
...
|
...
|
@@ -22,20 +23,22 @@ class API { |
|
|
*/
|
|
|
get(url, data) {
|
|
|
|
|
|
log.info('API GET: %s, parms: %j',url,data,{});
|
|
|
log.profile('%s %j',url,data);
|
|
|
|
|
|
let ret = rp({
|
|
|
let options = {
|
|
|
url: `${ApiUrl}${url}`,
|
|
|
qs: data
|
|
|
});
|
|
|
};
|
|
|
|
|
|
let timer = new Timer();
|
|
|
timer.put('getApi');//统计时间开始
|
|
|
|
|
|
let ret = rp(options);
|
|
|
|
|
|
ret.then((body)=>{
|
|
|
log.profile('%s %j',url,data);
|
|
|
log.info('API GET: %s, parms: %j ',url,data,body);
|
|
|
let duration = timer.put('getApi');//接口返回
|
|
|
log.info('API GET: %s, parms: %j , durationMs: %d ms , body: %s',options.url,options.qs,duration,body);
|
|
|
}).catch((error)=>{
|
|
|
log.profile('%s %j',url,data);
|
|
|
log.error('API GET: %s, parms: %j ',url,data,error);
|
|
|
let duration = timer.put('getApi');//接口返回
|
|
|
log.error('API GET: %s, parms: %j , durationMs: %d ms error: %s , statusCode: %d',options.url,options.qs,duration,error.message,error.statusCode);
|
|
|
});
|
|
|
|
|
|
return ret;
|
...
|
...
|
|