@onekeyfe/hd-shared 0.1.26 → 0.1.29
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/HardwareError.d.ts +5 -1
- package/dist/HardwareError.d.ts.map +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +13 -3
- package/package.json +2 -2
- package/src/HardwareError.ts +29 -3
package/dist/HardwareError.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export interface IHardwareError {
|
|
2
2
|
errorCode: ValueOf<typeof HardwareErrorCode>;
|
|
3
3
|
message?: string;
|
|
4
|
+
params?: any;
|
|
4
5
|
}
|
|
5
6
|
declare type ValueOf<P extends object> = P[keyof P];
|
|
6
7
|
declare type HardwareErrorCodeMessageMapping = {
|
|
@@ -10,6 +11,7 @@ declare type ErrorCodeUnion = ValueOf<typeof HardwareErrorCode>;
|
|
|
10
11
|
export declare class HardwareError extends Error {
|
|
11
12
|
errorCode: ErrorCodeUnion;
|
|
12
13
|
message: string;
|
|
14
|
+
params: any;
|
|
13
15
|
constructor(hardwareError: IHardwareError | string);
|
|
14
16
|
}
|
|
15
17
|
export declare const HardwareErrorCode: {
|
|
@@ -35,6 +37,8 @@ export declare const HardwareErrorCode: {
|
|
|
35
37
|
readonly CallMethodNotResponse: 404;
|
|
36
38
|
readonly CallMethodInvalidParameter: 405;
|
|
37
39
|
readonly FirmwareUpdateDownloadFailed: 406;
|
|
40
|
+
readonly CallMethodNeedUpgradeFirmware: 407;
|
|
41
|
+
readonly CallMethodDeprecated: 408;
|
|
38
42
|
readonly NetworkError: 500;
|
|
39
43
|
readonly TransportNotConfigured: 600;
|
|
40
44
|
readonly TransportCallInProgress: 601;
|
|
@@ -64,7 +68,7 @@ export declare const HardwareErrorCode: {
|
|
|
64
68
|
readonly PollingStop: 810;
|
|
65
69
|
};
|
|
66
70
|
export declare const HardwareErrorCodeMessage: HardwareErrorCodeMessageMapping;
|
|
67
|
-
export declare const TypedError: (hardwareError: ErrorCodeUnion | string, message?: string | undefined) => HardwareError;
|
|
71
|
+
export declare const TypedError: (hardwareError: ErrorCodeUnion | string, message?: string | undefined, params?: any) => HardwareError;
|
|
68
72
|
export declare const serializeError: (payload: any) => any;
|
|
69
73
|
export declare const CreateErrorByMessage: (message: string) => HardwareError;
|
|
70
74
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HardwareError.d.ts","sourceRoot":"","sources":["../src/HardwareError.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,OAAO,CAAC,OAAO,iBAAiB,CAAC,CAAC;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"HardwareError.d.ts","sourceRoot":"","sources":["../src/HardwareError.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,OAAO,CAAC,OAAO,iBAAiB,CAAC,CAAC;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,GAAG,CAAC;CACd;AAED,aAAK,OAAO,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;AAE5C,aAAK,+BAA+B,GAAG;KAAG,CAAC,IAAI,OAAO,CAAC,OAAO,iBAAiB,CAAC,GAAG,MAAM;CAAE,CAAC;AAE5F,aAAK,cAAc,GAAG,OAAO,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAOxD,qBAAa,aAAc,SAAQ,KAAK;IACtC,SAAS,EAAE,cAAc,CAAkC;IAE3D,OAAO,SAAM;IAEb,MAAM,EAAE,GAAG,CAAM;gBAEL,aAAa,EAAE,cAAc,GAAG,MAAM;CAmBnD;AAED,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0NpB,CAAC;AAEX,eAAO,MAAM,wBAAwB,EAAE,+BAmF7B,CAAC;AAEX,eAAO,MAAM,UAAU,kBACN,cAAc,GAAG,MAAM,yCAE7B,GAAG,kBAMb,CAAC;AAEF,eAAO,MAAM,cAAc,YAAa,GAAG,QAY1C,CAAC;AAEF,eAAO,MAAM,oBAAoB,YAAa,MAAM,KAAG,aAOtD,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ declare function createDeferred<T, I = any, D = any>(arg?: I, data?: D): Deferre
|
|
|
10
10
|
interface IHardwareError {
|
|
11
11
|
errorCode: ValueOf<typeof HardwareErrorCode>;
|
|
12
12
|
message?: string;
|
|
13
|
+
params?: any;
|
|
13
14
|
}
|
|
14
15
|
declare type ValueOf<P extends object> = P[keyof P];
|
|
15
16
|
declare type HardwareErrorCodeMessageMapping = {
|
|
@@ -19,6 +20,7 @@ declare type ErrorCodeUnion = ValueOf<typeof HardwareErrorCode>;
|
|
|
19
20
|
declare class HardwareError extends Error {
|
|
20
21
|
errorCode: ErrorCodeUnion;
|
|
21
22
|
message: string;
|
|
23
|
+
params: any;
|
|
22
24
|
constructor(hardwareError: IHardwareError | string);
|
|
23
25
|
}
|
|
24
26
|
declare const HardwareErrorCode: {
|
|
@@ -44,6 +46,8 @@ declare const HardwareErrorCode: {
|
|
|
44
46
|
readonly CallMethodNotResponse: 404;
|
|
45
47
|
readonly CallMethodInvalidParameter: 405;
|
|
46
48
|
readonly FirmwareUpdateDownloadFailed: 406;
|
|
49
|
+
readonly CallMethodNeedUpgradeFirmware: 407;
|
|
50
|
+
readonly CallMethodDeprecated: 408;
|
|
47
51
|
readonly NetworkError: 500;
|
|
48
52
|
readonly TransportNotConfigured: 600;
|
|
49
53
|
readonly TransportCallInProgress: 601;
|
|
@@ -73,7 +77,7 @@ declare const HardwareErrorCode: {
|
|
|
73
77
|
readonly PollingStop: 810;
|
|
74
78
|
};
|
|
75
79
|
declare const HardwareErrorCodeMessage: HardwareErrorCodeMessageMapping;
|
|
76
|
-
declare const TypedError: (hardwareError: ErrorCodeUnion | string, message?: string | undefined) => HardwareError;
|
|
80
|
+
declare const TypedError: (hardwareError: ErrorCodeUnion | string, message?: string | undefined, params?: any) => HardwareError;
|
|
77
81
|
declare const serializeError: (payload: any) => any;
|
|
78
82
|
declare const CreateErrorByMessage: (message: string) => HardwareError;
|
|
79
83
|
|
package/dist/index.js
CHANGED
|
@@ -65,6 +65,7 @@ class HardwareError extends Error {
|
|
|
65
65
|
super();
|
|
66
66
|
this.errorCode = HardwareErrorCode.UnknownError;
|
|
67
67
|
this.message = '';
|
|
68
|
+
this.params = {};
|
|
68
69
|
const errorMessageMapping = HardwareErrorCodeMessage;
|
|
69
70
|
this.message = errorMessageMapping[HardwareErrorCode.UnknownError];
|
|
70
71
|
if (typeof hardwareError === 'string') {
|
|
@@ -76,6 +77,7 @@ class HardwareError extends Error {
|
|
|
76
77
|
if (message) {
|
|
77
78
|
this.message = fillStringWithArguments(message, hardwareError);
|
|
78
79
|
}
|
|
80
|
+
this.params = hardwareError.params;
|
|
79
81
|
this.errorCode = hardwareError.errorCode;
|
|
80
82
|
}
|
|
81
83
|
this.name = 'HardwareError';
|
|
@@ -104,6 +106,8 @@ const HardwareErrorCode = {
|
|
|
104
106
|
CallMethodNotResponse: 404,
|
|
105
107
|
CallMethodInvalidParameter: 405,
|
|
106
108
|
FirmwareUpdateDownloadFailed: 406,
|
|
109
|
+
CallMethodNeedUpgradeFirmware: 407,
|
|
110
|
+
CallMethodDeprecated: 408,
|
|
107
111
|
NetworkError: 500,
|
|
108
112
|
TransportNotConfigured: 600,
|
|
109
113
|
TransportCallInProgress: 601,
|
|
@@ -155,6 +159,8 @@ const HardwareErrorCodeMessage = {
|
|
|
155
159
|
[HardwareErrorCode.CallMethodNotResponse]: 'Method does not responding',
|
|
156
160
|
[HardwareErrorCode.CallMethodInvalidParameter]: 'Call method invalid parameter',
|
|
157
161
|
[HardwareErrorCode.FirmwareUpdateDownloadFailed]: 'Firmware update download failed',
|
|
162
|
+
[HardwareErrorCode.CallMethodNeedUpgradeFirmware]: 'Call method need upgrade firmware',
|
|
163
|
+
[HardwareErrorCode.CallMethodDeprecated]: 'Call method is deprecated',
|
|
158
164
|
[HardwareErrorCode.NetworkError]: 'Network request error',
|
|
159
165
|
[HardwareErrorCode.TransportNotConfigured]: 'Transport not configured',
|
|
160
166
|
[HardwareErrorCode.TransportCallInProgress]: 'Transport call in progress',
|
|
@@ -183,15 +189,19 @@ const HardwareErrorCodeMessage = {
|
|
|
183
189
|
[HardwareErrorCode.PollingTimeout]: 'Polling timeout',
|
|
184
190
|
[HardwareErrorCode.PollingStop]: 'Polling stop',
|
|
185
191
|
};
|
|
186
|
-
const TypedError = (hardwareError, message) => {
|
|
192
|
+
const TypedError = (hardwareError, message, params) => {
|
|
187
193
|
if (typeof hardwareError === 'string') {
|
|
188
194
|
return new HardwareError(hardwareError);
|
|
189
195
|
}
|
|
190
|
-
return new HardwareError({ errorCode: hardwareError, message: message !== null && message !== void 0 ? message : '' });
|
|
196
|
+
return new HardwareError({ errorCode: hardwareError, message: message !== null && message !== void 0 ? message : '', params });
|
|
191
197
|
};
|
|
192
198
|
const serializeError = (payload) => {
|
|
193
199
|
if (payload && payload.error instanceof HardwareError) {
|
|
194
|
-
return {
|
|
200
|
+
return {
|
|
201
|
+
error: payload.error.message,
|
|
202
|
+
code: payload.error.errorCode,
|
|
203
|
+
params: payload.error.params,
|
|
204
|
+
};
|
|
195
205
|
}
|
|
196
206
|
if (payload && payload.error instanceof Error) {
|
|
197
207
|
return { error: payload.error.message, code: payload.error.code };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-shared",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.29",
|
|
4
4
|
"description": "Hardware SDK's shared tool library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Hardware-SDK",
|
|
@@ -25,5 +25,5 @@
|
|
|
25
25
|
"lint": "eslint .",
|
|
26
26
|
"lint:fix": "eslint . --fix"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "c90519ae4589f210f4d1cd582dec58ba046653a0"
|
|
29
29
|
}
|
package/src/HardwareError.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export interface IHardwareError {
|
|
2
2
|
errorCode: ValueOf<typeof HardwareErrorCode>;
|
|
3
3
|
message?: string;
|
|
4
|
+
params?: any;
|
|
4
5
|
}
|
|
5
6
|
|
|
6
7
|
type ValueOf<P extends object> = P[keyof P];
|
|
@@ -19,6 +20,8 @@ export class HardwareError extends Error {
|
|
|
19
20
|
|
|
20
21
|
message = '';
|
|
21
22
|
|
|
23
|
+
params: any = {};
|
|
24
|
+
|
|
22
25
|
constructor(hardwareError: IHardwareError | string) {
|
|
23
26
|
super();
|
|
24
27
|
const errorMessageMapping = HardwareErrorCodeMessage;
|
|
@@ -32,6 +35,7 @@ export class HardwareError extends Error {
|
|
|
32
35
|
if (message) {
|
|
33
36
|
this.message = fillStringWithArguments(message, hardwareError);
|
|
34
37
|
}
|
|
38
|
+
this.params = hardwareError.params;
|
|
35
39
|
this.errorCode = hardwareError.errorCode;
|
|
36
40
|
}
|
|
37
41
|
|
|
@@ -151,6 +155,18 @@ export const HardwareErrorCode = {
|
|
|
151
155
|
*/
|
|
152
156
|
FirmwareUpdateDownloadFailed: 406,
|
|
153
157
|
|
|
158
|
+
/**
|
|
159
|
+
* Call method not supported, need update firmware
|
|
160
|
+
* @params: { current: string, require: string }
|
|
161
|
+
*/
|
|
162
|
+
CallMethodNeedUpgradeFirmware: 407,
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Call method not supported, is deprecated
|
|
166
|
+
* @params: { current: string, deprecated: string }
|
|
167
|
+
*/
|
|
168
|
+
CallMethodDeprecated: 408,
|
|
169
|
+
|
|
154
170
|
/**
|
|
155
171
|
* Netword request error
|
|
156
172
|
*/
|
|
@@ -285,6 +301,8 @@ export const HardwareErrorCodeMessage: HardwareErrorCodeMessageMapping = {
|
|
|
285
301
|
[HardwareErrorCode.CallMethodNotResponse]: 'Method does not responding',
|
|
286
302
|
[HardwareErrorCode.CallMethodInvalidParameter]: 'Call method invalid parameter',
|
|
287
303
|
[HardwareErrorCode.FirmwareUpdateDownloadFailed]: 'Firmware update download failed',
|
|
304
|
+
[HardwareErrorCode.CallMethodNeedUpgradeFirmware]: 'Call method need upgrade firmware',
|
|
305
|
+
[HardwareErrorCode.CallMethodDeprecated]: 'Call method is deprecated',
|
|
288
306
|
|
|
289
307
|
/**
|
|
290
308
|
* Network Errors
|
|
@@ -330,16 +348,24 @@ export const HardwareErrorCodeMessage: HardwareErrorCodeMessageMapping = {
|
|
|
330
348
|
[HardwareErrorCode.PollingStop]: 'Polling stop',
|
|
331
349
|
} as const;
|
|
332
350
|
|
|
333
|
-
export const TypedError = (
|
|
351
|
+
export const TypedError = (
|
|
352
|
+
hardwareError: ErrorCodeUnion | string,
|
|
353
|
+
message?: string,
|
|
354
|
+
params?: any
|
|
355
|
+
) => {
|
|
334
356
|
if (typeof hardwareError === 'string') {
|
|
335
357
|
return new HardwareError(hardwareError);
|
|
336
358
|
}
|
|
337
|
-
return new HardwareError({ errorCode: hardwareError, message: message ?? '' });
|
|
359
|
+
return new HardwareError({ errorCode: hardwareError, message: message ?? '', params });
|
|
338
360
|
};
|
|
339
361
|
|
|
340
362
|
export const serializeError = (payload: any) => {
|
|
341
363
|
if (payload && payload.error instanceof HardwareError) {
|
|
342
|
-
return {
|
|
364
|
+
return {
|
|
365
|
+
error: payload.error.message,
|
|
366
|
+
code: payload.error.errorCode,
|
|
367
|
+
params: payload.error.params,
|
|
368
|
+
};
|
|
343
369
|
}
|
|
344
370
|
if (payload && payload.error instanceof Error) {
|
|
345
371
|
return { error: payload.error.message, code: payload.error.code };
|