@@ -60,9 +60,9 @@ var formatPath = function (path, path_params) {
6060
6161Mailchimp . prototype . post = function ( options , body , done ) {
6262
63- console . log ( JSON . stringify ( {
63+ console . log ( JSON . stringify ( {
6464 post_options : options ,
65- post_body : body
65+ post_body : body
6666 } ) ) ;
6767
6868 options = _ . clone ( options ) || { } ;
@@ -91,9 +91,9 @@ Mailchimp.prototype.post = function (options, body, done) {
9191}
9292
9393Mailchimp . prototype . patch = function ( options , body , done ) {
94- console . log ( JSON . stringify ( {
94+ console . log ( JSON . stringify ( {
9595 patch_options : options ,
96- patch_body : body
96+ patch_body : body
9797 } ) ) ;
9898
9999 options = _ . clone ( options ) || { } ;
@@ -123,7 +123,7 @@ Mailchimp.prototype.patch = function (options, body, done) {
123123
124124Mailchimp . prototype . request = function ( options , done ) {
125125 console . log ( JSON . stringify ( { request_options : options } ) ) ;
126-
126+
127127 var mailchimp = this ;
128128 var promise = new Promise ( function ( resolve , reject ) {
129129 if ( ! options ) {
@@ -161,18 +161,6 @@ Mailchimp.prototype.request = function (options, done) {
161161 }
162162
163163 let axios_req = {
164- method : method ,
165- url : mailchimp . __base_url + path ,
166- data : body ,
167- params : query ,
168- headers : headers ,
169- responseType : 'json' ,
170- }
171-
172- // omitted auth in log
173- console . log ( { axios_req } ) ;
174-
175- axios ( {
176164 method : method ,
177165 url : mailchimp . __base_url + path ,
178166 auth : {
@@ -183,32 +171,39 @@ Mailchimp.prototype.request = function (options, done) {
183171 params : query ,
184172 headers : headers ,
185173 responseType : 'json' ,
186- } , function ( err , response ) {
187-
188- if ( err ) {
189- var error = new Error ( err ) ;
190- console . log ( 'Mailchimp Error' , error . response ) ;
191- error . response = response ;
192- error . status = response ? response . status : undefined ;
193- reject ( error )
194- return ;
195- }
196-
197- console . log ( 'Mailchimp Response: ' , response )
198-
199- if ( response . status < 200 || response . status > 299 ) {
200- var error = Object . assign ( new Error ( response . data ? response . data : response . status ) , response . data || response )
201- error . response = response ;
202- error . status = response . status ;
203- reject ( error ) ;
204- return ;
205- }
174+ }
206175
207- var result = response . data || { } ;
208- result . statusCode = response . status ;
176+ // omitted auth in log
177+ console . log ( { axios_req } ) ;
209178
210- resolve ( result )
211- } )
179+ axios ( axios_req )
180+ . then ( ( response ) => {
181+
182+ console . log ( 'Mailchimp Response: ' , response )
183+
184+ if ( response . status < 200 || response . status > 299 ) {
185+ var error = Object . assign ( new Error ( response . data ? response . data : response . status ) , response . data || response )
186+ error . response = response ;
187+ error . status = response . status ;
188+ reject ( error ) ;
189+ return ;
190+ }
191+
192+ var result = response . data || { } ;
193+ result . statusCode = response . status ;
194+ resolve ( result )
195+ } )
196+ . catch ( ( err ) => {
197+ console . log ( 'Mailchimp Error: ' , err )
198+ if ( err ) {
199+ var error = new Error ( err ) ;
200+ console . log ( 'Mailchimp Error' , error . response ) ;
201+ error . response = response ;
202+ error . status = response ? response . status : undefined ;
203+ reject ( error )
204+ return ;
205+ }
206+ } ) ;
212207
213208 } )
214209
0 commit comments