Skip to content

Commit b87ac5d

Browse files
authored
Merge pull request #3 from initialstate/debug-logs
Debug logs
2 parents 8235630 + 3a2c7fb commit b87ac5d

1 file changed

Lines changed: 22 additions & 6 deletions

File tree

index.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ var formatPath = function (path, path_params) {
5757

5858

5959
Mailchimp.prototype.post = function (options, body, done) {
60-
options = _.clone(options) || {};
60+
options = _.clone(options) || {};
6161

6262
if (_.isString(options)) {
6363
options = {
@@ -83,7 +83,7 @@ Mailchimp.prototype.post = function (options, body, done) {
8383
}
8484

8585
Mailchimp.prototype.patch = function (options, body, done) {
86-
options = _.clone(options) || {};
86+
options = _.clone(options) || {};
8787

8888
if (_.isString(options)) {
8989
options = {
@@ -109,6 +109,8 @@ Mailchimp.prototype.patch = function (options, body, done) {
109109
}
110110

111111
Mailchimp.prototype.request = function (options, done) {
112+
console.log(JSON.stringify({ request_options: options }));
113+
112114
var mailchimp = this;
113115
var promise = new Promise(function(resolve, reject) {
114116
if (!options) {
@@ -118,17 +120,17 @@ Mailchimp.prototype.request = function (options, done) {
118120

119121
var path = formatPath(options.path, options.path_params);
120122
var method = options.method || 'get';
121-
var body = options.body || {};
123+
var body = options.body || {};
122124
var params = options.params;
123125
var query = options.query;
124126

125127
var headers = {
126-
'User-Agent' : 'mailchimp-api-v3 : https://github.com/thorning/node-mailchimp'
128+
'User-Agent' : 'mailchimp-api-v3 : https://github.com/initialstate/node-mailchimp'
127129
};
128130

129131
// Mailchimp does not respect on the language set in requests bodies for confirmation emails on new subscribers (and maybe other)
130132
// A workaround is to make sure the language header matches
131-
var language = options.language || body.language || null;
133+
var language = options.language || body.language || null;
132134
if (language) {
133135
headers['Accept-Language'] = language;
134136
}
@@ -145,6 +147,18 @@ Mailchimp.prototype.request = function (options, done) {
145147
return;
146148
}
147149

150+
let axios_req = {
151+
method : method,
152+
url : mailchimp.__base_url + path,
153+
data : body,
154+
params : query,
155+
headers : headers,
156+
responseType: 'json',
157+
}
158+
159+
// omitted auth in log
160+
console.log({ axios_req });
161+
148162
axios({
149163
method : method,
150164
url : mailchimp.__base_url + path,
@@ -160,13 +174,15 @@ Mailchimp.prototype.request = function (options, done) {
160174

161175
if (err) {
162176
var error = new Error(err);
163-
console.log('Error', error.response);
177+
console.log('Mailchimp Error', error.response);
164178
error.response = response;
165179
error.status = response ? response.status : undefined;
166180
reject(error)
167181
return;
168182
}
169183

184+
console.log('Mailchimp Response: ', response)
185+
170186
if (response.status < 200 || response.status > 299) {
171187
var error = Object.assign(new Error(response.data ? response.data : response.status), response.data || response)
172188
error.response = response;

0 commit comments

Comments
 (0)