@8ms/helpers 2.4.23 → 2.4.24

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.
@@ -15,7 +15,10 @@ const deleteRequest = async (url, config = {}) => {
15
15
  throwHttpErrors: false,
16
16
  ...config
17
17
  }).then(async (response) => {
18
- const data = await response.json();
18
+ const isJson = (response.headers.get("content-type") || "").includes("application/json");
19
+ let data;
20
+ if (isJson) data = await response.json();
21
+ else data = await response.text();
19
22
  if (void 0 !== data.body && void 0 !== data.error && void 0 !== data.state) return new require_api_ApiResponseClass.ApiResponseClass(data);
20
23
  else if (response.status >= 200 && response.status <= 299) return new require_api_ApiResponseClass.ApiResponseClass().setToSuccess(data);
21
24
  return new require_api_ApiResponseClass.ApiResponseClass().setToError(data, response.statusText);
@@ -12,7 +12,10 @@ const deleteRequest = async (url, config = {}) => {
12
12
  throwHttpErrors: false,
13
13
  ...config
14
14
  }).then(async (response) => {
15
- const data = await response.json();
15
+ const isJson = (response.headers.get("content-type") || "").includes("application/json");
16
+ let data;
17
+ if (isJson) data = await response.json();
18
+ else data = await response.text();
16
19
  if (void 0 !== data.body && void 0 !== data.error && void 0 !== data.state) return new ApiResponseClass(data);
17
20
  else if (response.status >= 200 && response.status <= 299) return new ApiResponseClass().setToSuccess(data);
18
21
  return new ApiResponseClass().setToError(data, response.statusText);
package/dist/api/get.cjs CHANGED
@@ -14,7 +14,10 @@ const get = async (url, config = {}) => {
14
14
  throwHttpErrors: false,
15
15
  ...config
16
16
  }).then(async (response) => {
17
- const data = await response.json();
17
+ const isJson = (response.headers.get("content-type") || "").includes("application/json");
18
+ let data;
19
+ if (isJson) data = await response.json();
20
+ else data = await response.text();
18
21
  if (void 0 !== data.body && void 0 !== data.error && void 0 !== data.state) return new require_api_ApiResponseClass.ApiResponseClass(data);
19
22
  else if (response.status >= 200 && response.status <= 299) return new require_api_ApiResponseClass.ApiResponseClass().setToSuccess(data);
20
23
  return new require_api_ApiResponseClass.ApiResponseClass().setToError(data, response.statusText);
package/dist/api/get.mjs CHANGED
@@ -11,7 +11,10 @@ const get = async (url, config = {}) => {
11
11
  throwHttpErrors: false,
12
12
  ...config
13
13
  }).then(async (response) => {
14
- const data = await response.json();
14
+ const isJson = (response.headers.get("content-type") || "").includes("application/json");
15
+ let data;
16
+ if (isJson) data = await response.json();
17
+ else data = await response.text();
15
18
  if (void 0 !== data.body && void 0 !== data.error && void 0 !== data.state) return new ApiResponseClass(data);
16
19
  else if (response.status >= 200 && response.status <= 299) return new ApiResponseClass().setToSuccess(data);
17
20
  return new ApiResponseClass().setToError(data, response.statusText);
package/dist/api/post.cjs CHANGED
@@ -15,10 +15,13 @@ const post = async (url, data = {}, config = {}) => {
15
15
  throwHttpErrors: false,
16
16
  ...config
17
17
  }).then(async (response) => {
18
- const responseData = await response.json();
19
- if (void 0 !== responseData.body && void 0 !== responseData.error && void 0 !== responseData.state) return new require_api_ApiResponseClass.ApiResponseClass(responseData);
20
- else if (response.status >= 200 && response.status <= 299) return new require_api_ApiResponseClass.ApiResponseClass().setToSuccess(responseData);
21
- return new require_api_ApiResponseClass.ApiResponseClass().setToError(responseData, response.statusText);
18
+ const isJson = (response.headers.get("content-type") || "").includes("application/json");
19
+ let data;
20
+ if (isJson) data = await response.json();
21
+ else data = await response.text();
22
+ if (void 0 !== data.body && void 0 !== data.error && void 0 !== data.state) return new require_api_ApiResponseClass.ApiResponseClass(data);
23
+ else if (response.status >= 200 && response.status <= 299) return new require_api_ApiResponseClass.ApiResponseClass().setToSuccess(data);
24
+ return new require_api_ApiResponseClass.ApiResponseClass().setToError(data, response.statusText);
22
25
  }).catch((error) => {
23
26
  return new require_api_ApiResponseClass.ApiResponseClass().setToError(null, error.message);
24
27
  });
package/dist/api/post.mjs CHANGED
@@ -12,10 +12,13 @@ const post = async (url, data = {}, config = {}) => {
12
12
  throwHttpErrors: false,
13
13
  ...config
14
14
  }).then(async (response) => {
15
- const responseData = await response.json();
16
- if (void 0 !== responseData.body && void 0 !== responseData.error && void 0 !== responseData.state) return new ApiResponseClass(responseData);
17
- else if (response.status >= 200 && response.status <= 299) return new ApiResponseClass().setToSuccess(responseData);
18
- return new ApiResponseClass().setToError(responseData, response.statusText);
15
+ const isJson = (response.headers.get("content-type") || "").includes("application/json");
16
+ let data;
17
+ if (isJson) data = await response.json();
18
+ else data = await response.text();
19
+ if (void 0 !== data.body && void 0 !== data.error && void 0 !== data.state) return new ApiResponseClass(data);
20
+ else if (response.status >= 200 && response.status <= 299) return new ApiResponseClass().setToSuccess(data);
21
+ return new ApiResponseClass().setToError(data, response.statusText);
19
22
  }).catch((error) => {
20
23
  return new ApiResponseClass().setToError(null, error.message);
21
24
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@8ms/helpers",
3
3
  "license": "UNLICENSED",
4
- "version": "2.4.23",
4
+ "version": "2.4.24",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"