@abtnode/util 1.8.0 → 1.8.3

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/lib/axios.js CHANGED
@@ -2,6 +2,4 @@
2
2
  // https://github.com/axios/axios/issues/3384
3
3
  const { default: axios } = require('axios');
4
4
 
5
- axios.defaults.proxy = false;
6
-
7
5
  module.exports = axios;
@@ -6,6 +6,39 @@ const axios = require('./axios');
6
6
 
7
7
  const CANCEL = '__cancel__';
8
8
 
9
+ /**
10
+ *
11
+ *
12
+ * @param {Stream} stream
13
+ * @returns {Promise<string>}
14
+ */
15
+ async function getErrorMessageFromStream(stream) {
16
+ const str = await streamToString(stream);
17
+
18
+ try {
19
+ const json = JSON.parse(str);
20
+ return json.error;
21
+ } catch (error) {
22
+ return str;
23
+ }
24
+ }
25
+
26
+ /**
27
+ *
28
+ *
29
+ * @param {*} stream
30
+ * @return {Promise<string>}
31
+ */
32
+ async function streamToString(stream) {
33
+ const chunks = [];
34
+
35
+ for await (const chunk of stream) {
36
+ chunks.push(Buffer.from(chunk));
37
+ }
38
+
39
+ return Buffer.concat(chunks).toString('utf-8');
40
+ }
41
+
9
42
  /**
10
43
  *
11
44
  *
@@ -80,6 +113,11 @@ const downloadFile = async (url, dest, { timeout = 600 * 1000, cancelCtrl } = {}
80
113
  }
81
114
 
82
115
  source.cancel();
116
+
117
+ if (err?.response?.data) {
118
+ throw new Error(await getErrorMessageFromStream(err.response.data));
119
+ }
120
+
83
121
  throw err;
84
122
  }
85
123
  };
package/lib/sleep.js CHANGED
@@ -1 +1,2 @@
1
+ // eslint-disable-next-line no-promise-executor-return
1
2
  module.exports = (timeout = 0) => new Promise((resolve) => setTimeout(resolve, timeout));
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.8.0",
6
+ "version": "1.8.3",
7
7
  "description": "ArcBlock's JavaScript utility",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -18,10 +18,12 @@
18
18
  "author": "polunzh <polunzh@gmail.com> (http://github.com/polunzh)",
19
19
  "license": "MIT",
20
20
  "dependencies": {
21
- "@abtnode/constant": "1.8.0",
22
- "@ocap/mcrypto": "1.17.0",
23
- "@ocap/util": "1.17.0",
24
- "@ocap/wallet": "1.17.0",
21
+ "@abtnode/constant": "1.8.3",
22
+ "@abtnode/logger": "1.8.3",
23
+ "@arcblock/jwt": "^1.17.5",
24
+ "@ocap/mcrypto": "1.17.5",
25
+ "@ocap/util": "1.17.5",
26
+ "@ocap/wallet": "1.17.5",
25
27
  "axios": "^0.27.2",
26
28
  "axios-mock-adapter": "^1.20.0",
27
29
  "axon": "^2.0.3",
@@ -56,5 +58,5 @@
56
58
  "fs-extra": "^10.0.1",
57
59
  "jest": "^27.4.5"
58
60
  },
59
- "gitHead": "6446a85fb33721abc24bb1045d59158e6b96c241"
61
+ "gitHead": "c734aca7bf1fc03378c3b082d0622b6a540a8bd3"
60
62
  }