diff --git a/.gitignore b/.gitignore index e920c16..31198c6 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,6 @@ node_modules # Optional REPL history .node_repl_history + +.idea/ +yarn.lock diff --git a/lib/apicontrollersbase.js b/lib/apicontrollersbase.js index 877c91b..181bfa1 100644 --- a/lib/apicontrollersbase.js +++ b/lib/apicontrollersbase.js @@ -1,9 +1,10 @@ 'use strict'; -var request = require('request'); +var got = require('got'); var logger = require('./logger.js').logger; var config = require('./config').config; var constants = require('./constants').constants; +var hpagent = require('hpagent'); class APIOperationBase { constructor(apiRequest) { @@ -80,43 +81,32 @@ class APIOperationBase { logger.debug(JSON.stringify(this._request, 2, null)); - var reqOpts = { - url: this._endpoint, - method: 'POST', - json: true, - timeout: config.timeout, - body: this._request - }; + var reqOpts = { timeout: config.timeout, json: this._request, method: 'POST' }; - if(config.proxy.setProxy){ - reqOpts['proxy'] = config.proxy.proxyUrl; + if (config.proxy.setProxy) { + reqOpts['agent'] = { + https: new hpagent.HttpsProxyAgent({ + proxy: config.proxy.proxyUrl + }) + }; } - request(reqOpts, function(error, response, body){ - if(error) { - logger.error(error); - } else - { - //TODO: slice added due to BOM character. remove once BOM character is removed. - if(typeof body!=='undefined'){ - var responseObj = JSON.parse(body.slice(1)); + got(this._endpoint, reqOpts) + .then(response => { + const body = response.body; + // TODO: slice added due to BOM character. remove once BOM character is removed. + if (typeof body !== 'undefined') { + const responseObj = JSON.parse(body.slice(1)); logger.debug(JSON.stringify(responseObj, 2, null)); obj._response = responseObj; - /* - var jsonResponse = JSON.stringify(body); - console.log("escaped body : '" + escape(jsonResponse) + "'"); - console.log("body : '" + jsonResponse + "'"); - logger.debug("Response: " + JSON.stringify(body, 2, null)); - obj._response = body; - */ - callback(); - } - else - { - logger.error("Undefined Response"); + callback(); + } else { + logger.error('Undefined Response'); } - } - }); + }) + .catch(error => { + logger.error(error); + }); logger.debug('Exit APIOperationBase execute'); } diff --git a/package.json b/package.json index 853f166..7c4f843 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "test": "tests" }, "dependencies": { - "request": "^2.72.0", + "got": "^13.0.0", + "hpagent": "^1.2.0", "winston": "^2.2.0" }, "devDependencies": {