@selkirk-systems/fetch 0.1.4 → 0.1.6

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.js CHANGED
@@ -11,29 +11,27 @@ var _networkTimer = null;
11
11
  function _checkFetchStatus(response) {
12
12
  if (response.status >= 200 && response.status < 300) {
13
13
  return response.text().then(function (text) {
14
- return text ? JSON.parse(text) : {};
14
+ try {
15
+ return text ? JSON.parse(text) : {};
16
+ } catch (e) {
17
+ return text;
18
+ }
15
19
  });
16
20
  } else {
17
21
  var error = new Error(response.statusText);
18
22
  return response.text().then(function (text) {
19
23
  if (text) {
20
- JSON.parse(text).json().then(function (result) {
21
- error.response = result;
22
- throw error;
23
- });
24
- } else {
25
- throw error;
24
+ try {
25
+ error.response = JSON.parse(text);
26
+ } catch (e) {
27
+ error.response = text;
28
+ }
26
29
  }
30
+ throw error;
27
31
  });
28
32
  }
29
33
  }
30
34
 
31
- function _parseJSON(response) {
32
- return response.text().then(function (text) {
33
- return text ? JSON.parse(text) : {};
34
- });
35
- }
36
-
37
35
  function _invokeFetch(url, props) {
38
36
  if (!url) {
39
37
  throw new Error("fetch:Missing Parameter - URL");