@openfn/language-mailchimp 0.8.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +28 -15
- package/dist/index.js +28 -15
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -252,17 +252,23 @@ var defaultOptions = {
|
|
|
252
252
|
query: {},
|
|
253
253
|
body: void 0
|
|
254
254
|
};
|
|
255
|
-
var assertOK = (response, fullUrl) => {
|
|
256
|
-
if (response.
|
|
257
|
-
const
|
|
258
|
-
|
|
255
|
+
var assertOK = async (response, fullUrl) => {
|
|
256
|
+
if (response.statusCode >= 400) {
|
|
257
|
+
const message = `Request to ${fullUrl} failed with status: ${response.statusCode}`;
|
|
258
|
+
console.error(message);
|
|
259
|
+
let mailchimpError;
|
|
260
|
+
try {
|
|
261
|
+
mailchimpError = await response.body.json();
|
|
262
|
+
} catch (e) {
|
|
263
|
+
console.warning("Error parsing mailchimp error body");
|
|
264
|
+
console.warning(e);
|
|
265
|
+
}
|
|
266
|
+
if (mailchimpError) {
|
|
267
|
+
throw mailchimpError;
|
|
268
|
+
}
|
|
269
|
+
const error = new Error(message);
|
|
270
|
+
error.status = response.statusCode;
|
|
259
271
|
error.url = fullUrl;
|
|
260
|
-
error.type = response.type;
|
|
261
|
-
error.title = response.title;
|
|
262
|
-
error.status = response.status;
|
|
263
|
-
error.detail = response.detail;
|
|
264
|
-
error.instance = response.instance;
|
|
265
|
-
error.errors = response.errors;
|
|
266
272
|
throw error;
|
|
267
273
|
}
|
|
268
274
|
};
|
|
@@ -292,13 +298,20 @@ function request(method, path, options, callback) {
|
|
|
292
298
|
query,
|
|
293
299
|
body: body ? JSON.stringify(body) : void 0
|
|
294
300
|
});
|
|
295
|
-
console.log(
|
|
296
|
-
|
|
297
|
-
|
|
301
|
+
console.log(response.statusCode, urlPath);
|
|
302
|
+
await assertOK(response, `https://${server}.api.mailchimp.com${urlPath}`);
|
|
303
|
+
let data = {};
|
|
304
|
+
if (response.statusCode !== 204) {
|
|
305
|
+
data = await response.body.json();
|
|
306
|
+
}
|
|
298
307
|
const nextState = {
|
|
299
308
|
...state,
|
|
300
|
-
data
|
|
301
|
-
response:
|
|
309
|
+
data,
|
|
310
|
+
response: {
|
|
311
|
+
headers: response.headers,
|
|
312
|
+
body: data,
|
|
313
|
+
statusCode: response.statusCode
|
|
314
|
+
}
|
|
302
315
|
};
|
|
303
316
|
if (callback)
|
|
304
317
|
return callback(nextState);
|
package/dist/index.js
CHANGED
|
@@ -210,17 +210,23 @@ var defaultOptions = {
|
|
|
210
210
|
query: {},
|
|
211
211
|
body: void 0
|
|
212
212
|
};
|
|
213
|
-
var assertOK = (response, fullUrl) => {
|
|
214
|
-
if (response.
|
|
215
|
-
const
|
|
216
|
-
|
|
213
|
+
var assertOK = async (response, fullUrl) => {
|
|
214
|
+
if (response.statusCode >= 400) {
|
|
215
|
+
const message = `Request to ${fullUrl} failed with status: ${response.statusCode}`;
|
|
216
|
+
console.error(message);
|
|
217
|
+
let mailchimpError;
|
|
218
|
+
try {
|
|
219
|
+
mailchimpError = await response.body.json();
|
|
220
|
+
} catch (e) {
|
|
221
|
+
console.warning("Error parsing mailchimp error body");
|
|
222
|
+
console.warning(e);
|
|
223
|
+
}
|
|
224
|
+
if (mailchimpError) {
|
|
225
|
+
throw mailchimpError;
|
|
226
|
+
}
|
|
227
|
+
const error = new Error(message);
|
|
228
|
+
error.status = response.statusCode;
|
|
217
229
|
error.url = fullUrl;
|
|
218
|
-
error.type = response.type;
|
|
219
|
-
error.title = response.title;
|
|
220
|
-
error.status = response.status;
|
|
221
|
-
error.detail = response.detail;
|
|
222
|
-
error.instance = response.instance;
|
|
223
|
-
error.errors = response.errors;
|
|
224
230
|
throw error;
|
|
225
231
|
}
|
|
226
232
|
};
|
|
@@ -250,13 +256,20 @@ function request(method, path, options, callback) {
|
|
|
250
256
|
query,
|
|
251
257
|
body: body ? JSON.stringify(body) : void 0
|
|
252
258
|
});
|
|
253
|
-
console.log(
|
|
254
|
-
|
|
255
|
-
|
|
259
|
+
console.log(response.statusCode, urlPath);
|
|
260
|
+
await assertOK(response, `https://${server}.api.mailchimp.com${urlPath}`);
|
|
261
|
+
let data = {};
|
|
262
|
+
if (response.statusCode !== 204) {
|
|
263
|
+
data = await response.body.json();
|
|
264
|
+
}
|
|
256
265
|
const nextState = {
|
|
257
266
|
...state,
|
|
258
|
-
data
|
|
259
|
-
response:
|
|
267
|
+
data,
|
|
268
|
+
response: {
|
|
269
|
+
headers: response.headers,
|
|
270
|
+
body: data,
|
|
271
|
+
statusCode: response.statusCode
|
|
272
|
+
}
|
|
260
273
|
};
|
|
261
274
|
if (callback)
|
|
262
275
|
return callback(nextState);
|