Skip to content
This repository has been archived by the owner on Jul 23, 2020. It is now read-only.

Commit

Permalink
feat: debug for request
Browse files Browse the repository at this point in the history
  • Loading branch information
VladimirPal committed Mar 19, 2018
1 parent 203fa73 commit cfddb6a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
7 changes: 4 additions & 3 deletions api/myself.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ function MyselfClient(jiraClient) {
* @param [callback] Called when the current user is retrieved.
* @return {Promise} Resolved when the current user is retrieved.
*/
this.getMyself = function (opts, callback) {
this.getMyself = function (debug, callback) {
var options = {
uri: this.jiraClient.buildURL('/myself'),
method: 'GET',
json: true,
followAllRedirects: true
followAllRedirects: true,
debug: debug,
};

return this.jiraClient.makeRequest(options, callback);
Expand Down Expand Up @@ -75,4 +76,4 @@ function MyselfClient(jiraClient) {

return this.jiraClient.makeRequest(options, callback);
}
}
}
43 changes: 41 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ var JiraClient = module.exports = function (config) {
this.webhookApiVersion = '1.0';
this.promise = config.promise || Promise;
this.requestLib = config.request || request;
this.rejectUnauthorized = config.rejectUnauthorized || true;
this.rejectUnauthorized = config.rejectUnauthorized;

if (config.oauth) {
if (!config.oauth.consumer_key) {
Expand Down Expand Up @@ -371,6 +371,11 @@ var JiraClient = module.exports = function (config) {
return new this.promise(function (resolve, reject) {

var req = requestLib(options);
var requestObj = null;

req.on('request', function(request) {
requestObj = request;
});

req.on('response', function(response) {

Expand Down Expand Up @@ -398,11 +403,45 @@ var JiraClient = module.exports = function (config) {

if (error) {
response.body = result;
reject(JSON.stringify(response));
if (options.debug) {
reject({
result: JSON.stringify(response),
debug: {
options: options,
request: {
headers: requestObj._headers,
rawHeaders: requestObj._header,
},
response: {
headers: response.headers,
rawHeaders: response.rawHeaders,
},
}
});
} else {
reject(JSON.stringify(response));
}
return;
}

if (options.debug) {
resolve({
result,
debug: {
options: options,
request: {
headers: requestObj._headers,
rawHeaders: requestObj._header,
},
response: {
headers: response.headers,
rawHeaders: response.rawHeaders,
},
}
});
} else {
resolve(result);
}
});

});
Expand Down

0 comments on commit cfddb6a

Please sign in to comment.