Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 36 additions & 41 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ var formatPath = function (path, path_params) {

Mailchimp.prototype.post = function (options, body, done) {

console.log(JSON.stringify({
console.log(JSON.stringify({
post_options: options,
post_body: body
post_body: body
}));

options = _.clone(options) || {};
Expand Down Expand Up @@ -91,9 +91,9 @@ Mailchimp.prototype.post = function (options, body, done) {
}

Mailchimp.prototype.patch = function (options, body, done) {
console.log(JSON.stringify({
console.log(JSON.stringify({
patch_options: options,
patch_body: body
patch_body: body
}));

options = _.clone(options) || {};
Expand Down Expand Up @@ -123,7 +123,7 @@ Mailchimp.prototype.patch = function (options, body, done) {

Mailchimp.prototype.request = function (options, done) {
console.log(JSON.stringify({ request_options: options }));

var mailchimp = this;
var promise = new Promise(function(resolve, reject) {
if (!options) {
Expand Down Expand Up @@ -161,18 +161,6 @@ Mailchimp.prototype.request = function (options, done) {
}

let axios_req = {
method : method,
url : mailchimp.__base_url + path,
data : body,
params : query,
headers : headers,
responseType: 'json',
}

// omitted auth in log
console.log({ axios_req });

axios({
method : method,
url : mailchimp.__base_url + path,
auth : {
Expand All @@ -183,32 +171,39 @@ Mailchimp.prototype.request = function (options, done) {
params : query,
headers : headers,
responseType: 'json',
}, function (err, response) {

if (err) {
var error = new Error(err);
console.log('Mailchimp Error', error.response);
error.response = response;
error.status = response ? response.status : undefined;
reject(error)
return;
}

console.log('Mailchimp Response: ', response)

if (response.status < 200 || response.status > 299) {
var error = Object.assign(new Error(response.data ? response.data : response.status), response.data || response)
error.response = response;
error.status = response.status;
reject(error);
return;
}
}

var result = response.data || {};
result.statusCode = response.status;
// omitted auth in log
console.log({ axios_req });

resolve(result)
})
axios(axios_req)
.then((response) => {

console.log('Mailchimp Response: ', response)

if (response.status < 200 || response.status > 299) {
var error = Object.assign(new Error(response.data ? response.data : response.status), response.data || response)
error.response = response;
error.status = response.status;
reject(error);
return;
}

var result = response.data || {};
result.statusCode = response.status;
resolve(result)
})
.catch((err) => {
console.log('Mailchimp Error: ', err)
if (err) {
var error = new Error(err);
console.log('Mailchimp Error', error.response);
error.response = response;
error.status = response ? response.status : undefined;
reject(error)
return;
}
});

})

Expand Down