nylas 6.4.0 → 6.4.1

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.
@@ -193,30 +193,22 @@ var NylasConnection = /** @class */ (function () {
193
193
  console.warn(warning);
194
194
  }
195
195
  if (response.status > 299) {
196
- return response
197
- .clone()
198
- .json()
199
- .then(function (body) {
200
- var error = new nylas_api_error_1.default(response.status, body.type, body.message);
201
- if (body.missing_fields) {
202
- error.missingFields = body.missing_fields;
203
- }
204
- if (body.server_error) {
205
- error.serverError = body.server_error;
206
- }
207
- return reject(error);
208
- })
209
- .catch(function () {
210
- return response
211
- .text()
212
- .then(function (text) {
213
- var error = new nylas_api_error_1.default(response.status, response.statusText, text);
196
+ return response.text().then(function (body) {
197
+ try {
198
+ var parsedApiError = JSON.parse(body);
199
+ var error = new nylas_api_error_1.default(response.status, parsedApiError.type, parsedApiError.message);
200
+ if (parsedApiError.missing_fields) {
201
+ error.missingFields = parsedApiError.missing_fields;
202
+ }
203
+ if (parsedApiError.server_error) {
204
+ error.serverError = parsedApiError.server_error;
205
+ }
214
206
  return reject(error);
215
- })
216
- .catch(function () {
217
- var error = new nylas_api_error_1.default(response.status, response.statusText, 'Error encountered during request, unable to extract error message.');
207
+ }
208
+ catch (e) {
209
+ var error = new nylas_api_error_1.default(response.status, response.statusText, body);
218
210
  return reject(error);
219
- });
211
+ }
220
212
  });
221
213
  }
222
214
  else {
@@ -244,12 +236,14 @@ var NylasConnection = /** @class */ (function () {
244
236
  return resolve(response.text());
245
237
  }
246
238
  else {
247
- return response
248
- .clone()
249
- .json()
250
- .catch(function () { return response.text(); })
251
- .then(function (data) { return resolve(data); })
252
- .catch(function () { return resolve(undefined); });
239
+ return response.text().then(function (text) {
240
+ try {
241
+ return resolve(JSON.parse(text));
242
+ }
243
+ catch (e) {
244
+ return resolve(text);
245
+ }
246
+ });
253
247
  }
254
248
  }
255
249
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nylas",
3
- "version": "6.4.0",
3
+ "version": "6.4.1",
4
4
  "description": "A NodeJS wrapper for the Nylas REST API for email, contacts, and calendar.",
5
5
  "main": "lib/nylas.js",
6
6
  "types": "lib/nylas.d.ts",