@onekeyfe/hd-transport-http 0.1.53 → 0.1.55
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/http.d.ts.map +1 -1
- package/dist/index.js +6 -2
- package/package.json +4 -4
- package/src/http.ts +6 -2
package/dist/http.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAGA,oBAAY,kBAAkB,GAAG;IAC/B,IAAI,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC;IACrD,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,GAAG,KAAK,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAGA,oBAAY,kBAAkB,GAAG;IAC/B,IAAI,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC;IACrD,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,GAAG,KAAK,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AA4BF,wBAAsB,OAAO,CAAC,OAAO,EAAE,kBAAkB,gBA0BxD"}
|
package/dist/index.js
CHANGED
|
@@ -48,7 +48,11 @@ function wrapBody(body) {
|
|
|
48
48
|
}
|
|
49
49
|
function parseResult(text) {
|
|
50
50
|
try {
|
|
51
|
-
|
|
51
|
+
const result = JSON.parse(text);
|
|
52
|
+
if (typeof result !== 'object') {
|
|
53
|
+
throw new Error('Invalid response');
|
|
54
|
+
}
|
|
55
|
+
return result;
|
|
52
56
|
}
|
|
53
57
|
catch (e) {
|
|
54
58
|
return text;
|
|
@@ -69,7 +73,7 @@ function request(options) {
|
|
|
69
73
|
};
|
|
70
74
|
const res = yield axios__default["default"].request(fetchOptions);
|
|
71
75
|
if (+res.status === 200) {
|
|
72
|
-
return parseResult(res.
|
|
76
|
+
return parseResult(res.request.responseText);
|
|
73
77
|
}
|
|
74
78
|
const resJson = parseResult(res.data);
|
|
75
79
|
if (typeof resJson === 'object' && resJson != null && resJson.error != null) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-transport-http",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.55",
|
|
4
4
|
"description": "hardware http transport",
|
|
5
5
|
"author": "OneKey",
|
|
6
6
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
"url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@onekeyfe/hd-shared": "^0.1.
|
|
29
|
-
"@onekeyfe/hd-transport": "^0.1.
|
|
28
|
+
"@onekeyfe/hd-shared": "^0.1.55",
|
|
29
|
+
"@onekeyfe/hd-transport": "^0.1.55",
|
|
30
30
|
"axios": "^0.27.2"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "79fa201d009fc80a31946cd40f889b37f1ec53b0"
|
|
33
33
|
}
|
package/src/http.ts
CHANGED
|
@@ -24,7 +24,11 @@ function wrapBody(body: any) {
|
|
|
24
24
|
|
|
25
25
|
function parseResult(text: string) {
|
|
26
26
|
try {
|
|
27
|
-
|
|
27
|
+
const result = JSON.parse(text);
|
|
28
|
+
if (typeof result !== 'object') {
|
|
29
|
+
throw new Error('Invalid response');
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
28
32
|
} catch (e) {
|
|
29
33
|
return text;
|
|
30
34
|
}
|
|
@@ -45,7 +49,7 @@ export async function request(options: HttpRequestOptions) {
|
|
|
45
49
|
const res = await axios.request(fetchOptions);
|
|
46
50
|
|
|
47
51
|
if (+res.status === 200) {
|
|
48
|
-
return parseResult(res.
|
|
52
|
+
return parseResult(res.request.responseText);
|
|
49
53
|
}
|
|
50
54
|
const resJson = parseResult(res.data);
|
|
51
55
|
if (typeof resJson === 'object' && resJson != null && resJson.error != null) {
|