systemlynx 1.12.10 → 1.13.10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "systemlynx",
3
- "version": "1.12.10",
3
+ "version": "1.13.10",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "browser": {
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  const { isNode } = require("../../../utils/ProcessChecker");
4
- const { convertToReadStream } = require("../components/convertToReadStream");
4
+ const { convertToReadStream } = require("./convertToReadStream");
5
5
  const isObject = (value) =>
6
6
  typeof value === "object" ? (!value ? false : !Array.isArray(value)) : false;
7
7
  const isEmpty = (obj) => Object.getOwnPropertyNames(obj).length === 0;
@@ -63,12 +63,8 @@ module.exports = function ServiceRequestHandler(
63
63
  };
64
64
 
65
65
  const ErrorHandler = (err, errCount, cb) => {
66
- if (!err.isAxiosError) throw err;
67
- if (!err.response) throw err;
68
- if (!err.response.data) throw err;
69
-
70
- if (err.response.data.SystemLynxService) {
71
- cb(err.response.data);
66
+ if (err.SystemLynxService) {
67
+ cb(err);
72
68
  } else if (errCount <= 3) {
73
69
  errCount++;
74
70
  if (reconnectModule) reconnectModule(() => tryRequest(cb, errCount));
@@ -7,10 +7,15 @@ module.exports = function createHttpClient() {
7
7
  const Client = {};
8
8
  Client.request = async ({ method = "get", url, body: data, headers }) => {
9
9
  method = method.toLowerCase();
10
- const res = await axios({ url, method, headers, data });
11
- if (res.status >= 400) {
12
- throw res.data;
13
- } else return res.data;
10
+ try {
11
+ const res = await axios({ url, method, headers, data });
12
+ return res.data;
13
+ } catch (error) {
14
+ if (!error.isAxiosError) throw error;
15
+ if (!error.response) throw error;
16
+ if (!error.response.data) throw error;
17
+ throw error.response.data;
18
+ }
14
19
  };
15
20
 
16
21
  Client.upload = async ({ url, formData, headers }) => {
@@ -24,12 +29,17 @@ module.exports = function createHttpClient() {
24
29
  }
25
30
  if (__arguments) form.append("__arguments", JSON.stringify(__arguments));
26
31
 
27
- const res = await axios.post(url, form, {
28
- headers: { ...headers, "Content-Type": "multipart/form-data" },
29
- });
30
- if (res.status >= 400) {
31
- throw res.data;
32
- } else return res.data;
32
+ try {
33
+ const res = await axios.post(url, form, {
34
+ headers: { ...headers, "Content-Type": "multipart/form-data" },
35
+ });
36
+ return res.data;
37
+ } catch (error) {
38
+ if (!error.isAxiosError) throw error;
39
+ if (!error.response) throw error;
40
+ if (!error.response.data) throw error;
41
+ throw error.response.data;
42
+ }
33
43
  };
34
44
 
35
45
  return Client;