@dashevo/dapi-client 0.21.0-dev.11 → 0.21.0-dev.12
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.
|
@@ -2,6 +2,7 @@ const cbor = require('cbor');
|
|
|
2
2
|
|
|
3
3
|
const createConsensusError = require('@dashevo/dpp/lib/errors/consensus/createConsensusError');
|
|
4
4
|
const GrpcErrorCodes = require('@dashevo/grpc-common/lib/server/error/GrpcErrorCodes');
|
|
5
|
+
const { Metadata } = require('@grpc/grpc-js/build/src/metadata');
|
|
5
6
|
|
|
6
7
|
const NotFoundError = require('./errors/NotFoundError');
|
|
7
8
|
const TimeoutError = require('./errors/TimeoutError');
|
|
@@ -48,16 +49,30 @@ function createGrpcTransportError(grpcError, dapiAddress) {
|
|
|
48
49
|
let { code } = grpcError;
|
|
49
50
|
|
|
50
51
|
if (grpcError.metadata) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
let encodedData;
|
|
53
|
+
|
|
54
|
+
if (grpcError.metadata instanceof Metadata) {
|
|
55
|
+
const cboredMetaData = grpcError.metadata.get('drive-error-data-bin');
|
|
56
|
+
if (cboredMetaData && cboredMetaData.length > 0) {
|
|
57
|
+
[encodedData] = cboredMetaData;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// since gRPC doesn't allow to use custom error codes
|
|
61
|
+
// DAPI pass them as a part of metadata
|
|
62
|
+
const metaCode = grpcError.metadata.get('code');
|
|
63
|
+
if (metaCode && metaCode.length > 0) {
|
|
64
|
+
[code] = metaCode;
|
|
65
|
+
}
|
|
66
|
+
} else {
|
|
67
|
+
encodedData = Buffer.from(grpcError.metadata['drive-error-data-bin'], 'base64');
|
|
68
|
+
const metaCode = grpcError.metadata.code;
|
|
69
|
+
if (metaCode !== undefined) {
|
|
70
|
+
code = Number(metaCode);
|
|
71
|
+
}
|
|
54
72
|
}
|
|
55
73
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const metaCode = grpcError.metadata.get('code');
|
|
59
|
-
if (metaCode && metaCode.length > 0) {
|
|
60
|
-
[code] = metaCode;
|
|
74
|
+
if (encodedData) {
|
|
75
|
+
data = cbor.decode(encodedData);
|
|
61
76
|
}
|
|
62
77
|
}
|
|
63
78
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dashevo/dapi-client",
|
|
3
|
-
"version": "0.21.0-dev.
|
|
3
|
+
"version": "0.21.0-dev.12",
|
|
4
4
|
"description": "Client library used to access Dash DAPI endpoints",
|
|
5
5
|
"main": "lib/DAPIClient.js",
|
|
6
6
|
"contributors": [
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"@dashevo/dashcore-lib": "~0.19.26",
|
|
31
31
|
"@dashevo/dpp": "~0.21.0-dev.5",
|
|
32
32
|
"@dashevo/grpc-common": "~0.5.4",
|
|
33
|
+
"@grpc/grpc-js": "^1.3.7",
|
|
33
34
|
"axios": "^0.21.1",
|
|
34
35
|
"bs58": "^4.0.1",
|
|
35
36
|
"cbor": "^7.0.5",
|