@rsdk/grpc.clients 2.6.0-next.12 → 2.6.0-next.14
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/CHANGELOG.md +10 -0
- package/dist/middleware/exception-mapper.middleware.js +27 -3
- package/dist/middleware/exception-mapper.middleware.js.map +1 -1
- package/dist/servers/grpc.servers.js.map +1 -1
- package/package.json +9 -8
- package/src/middleware/exception-mapper.middleware.ts +40 -11
- package/src/servers/grpc.servers.ts +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,16 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [2.6.0-next.14](https://github.com/R-Vision/rsdk/compare/v2.6.0-next.13...v2.6.0-next.14) (2023-08-03)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* **grpc.clients:** grpc rich error ([#85](https://github.com/R-Vision/rsdk/issues/85)) ([be99f40](https://github.com/R-Vision/rsdk/commit/be99f408295bf1750f6f0c39e067cca971d973e3))
|
|
11
|
+
|
|
12
|
+
# [2.6.0-next.13](https://github.com/R-Vision/rsdk/compare/v2.6.0-next.12...v2.6.0-next.13) (2023-08-01)
|
|
13
|
+
|
|
14
|
+
**Note:** Version bump only for package @rsdk/grpc.clients
|
|
15
|
+
|
|
6
16
|
# [2.6.0-next.12](https://github.com/R-Vision/rsdk/compare/v2.6.0-next.11...v2.6.0-next.12) (2023-07-28)
|
|
7
17
|
|
|
8
18
|
**Note:** Version bump only for package @rsdk/grpc.clients
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.exceptionMapperMiddleware = void 0;
|
|
4
|
+
const error_1 = require("@rsdk/builtin-contract/dist/grpc/error/v1/error");
|
|
4
5
|
const core_1 = require("@rsdk/core");
|
|
5
6
|
const nice_grpc_1 = require("nice-grpc");
|
|
6
7
|
/**
|
|
@@ -9,8 +10,22 @@ const nice_grpc_1 = require("nice-grpc");
|
|
|
9
10
|
const exceptionMapperMiddleware = () =>
|
|
10
11
|
// eslint-disable-next-line unicorn/consistent-function-scoping
|
|
11
12
|
async function* (call, options) {
|
|
13
|
+
let status;
|
|
12
14
|
try {
|
|
13
|
-
return yield* call.next(call.request,
|
|
15
|
+
return yield* call.next(call.request, {
|
|
16
|
+
...options,
|
|
17
|
+
/**
|
|
18
|
+
* @link https://github.com/deeplay-io/nice-grpc/blob/2d781a477911b1d8a4a7b2faae27c7374ade8076/packages/nice-grpc-error-details/src/client/errorDetailsClientMiddleware.ts#L13
|
|
19
|
+
* @param trailer
|
|
20
|
+
*/
|
|
21
|
+
onTrailer(trailer) {
|
|
22
|
+
const detailsBuffer = trailer.get('grpc-status-details-bin');
|
|
23
|
+
if (detailsBuffer != null) {
|
|
24
|
+
status = error_1.Status.decode(detailsBuffer);
|
|
25
|
+
}
|
|
26
|
+
options.onTrailer?.(trailer);
|
|
27
|
+
},
|
|
28
|
+
});
|
|
14
29
|
}
|
|
15
30
|
catch (error) {
|
|
16
31
|
if (!(error instanceof nice_grpc_1.ClientError)) {
|
|
@@ -32,14 +47,23 @@ async function* (call, options) {
|
|
|
32
47
|
*/
|
|
33
48
|
path: error.path,
|
|
34
49
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
50
|
+
* A developer-facing error message, which should be in English. Any
|
|
51
|
+
* user-facing error message should be localized and sent in the
|
|
52
|
+
* [google.rpc.Status.details][google.rpc.Status.details] field, or localized by the client.
|
|
53
|
+
*
|
|
54
|
+
* https://github.com/deeplay-io/nice-grpc/blob/f0db4d130e1243db1cecb6586dca679e5d9b8fd5/packages/nice-grpc-error-details/proto/google/rpc/status.proto#L39
|
|
55
|
+
*/
|
|
56
|
+
statusMessage: status?.message,
|
|
57
|
+
/**
|
|
58
|
+
* any context from call
|
|
37
59
|
*/
|
|
60
|
+
details: status?.details,
|
|
38
61
|
},
|
|
39
62
|
};
|
|
40
63
|
/**
|
|
41
64
|
* According to /docs/images/exceptions.mapping.png
|
|
42
65
|
*/
|
|
66
|
+
// TODO: maybe replace to map and `Reflect.construct`
|
|
43
67
|
switch (error.code) {
|
|
44
68
|
case nice_grpc_1.Status.DEADLINE_EXCEEDED:
|
|
45
69
|
throw new core_1.TimeoutException(message, props);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exception-mapper.middleware.js","sourceRoot":"","sources":["../../src/middleware/exception-mapper.middleware.ts"],"names":[],"mappings":";;;AAAA,qCASoB;AACpB,
|
|
1
|
+
{"version":3,"file":"exception-mapper.middleware.js","sourceRoot":"","sources":["../../src/middleware/exception-mapper.middleware.ts"],"names":[],"mappings":";;;AAAA,2EAAyE;AACzE,qCASoB;AACpB,yCAAkE;AAGlE;;GAEG;AACI,MAAM,yBAAyB,GAAG,GAAqB,EAAE;AAC9D,+DAA+D;AAC/D,KAAK,SAAS,CAAC,EAAE,IAAI,EAAE,OAAO;IAC5B,IAAI,MAA0B,CAAC;IAE/B,IAAI;QACF,OAAO,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;YACpC,GAAG,OAAO;YACV;;;eAGG;YACH,SAAS,CAAC,OAAO;gBACf,MAAM,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;gBAE7D,IAAI,aAAa,IAAI,IAAI,EAAE;oBACzB,MAAM,GAAG,cAAM,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;iBACvC;gBAED,OAAO,CAAC,SAAS,EAAE,CAAC,OAAO,CAAC,CAAC;YAC/B,CAAC;SACF,CAAC,CAAC;KACJ;IAAC,OAAO,KAAc,EAAE;QACvB,IAAI,CAAC,CAAC,KAAK,YAAY,uBAAW,CAAC,EAAE;YACnC,MAAM,IAAI,wBAAiB,CAAC,qCAAqC,EAAE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C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grpc.servers.js","sourceRoot":"","sources":["../../src/servers/grpc.servers.ts"],"names":[],"mappings":";;;AAQA,MAAa,WAAW;IACtB,MAAM,CAAC,MAAM,CACX,WAAmC;QAEnC,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,GAAG,CACnD,CAAC,CAAC,UAAU,EAAE,UAAU,CAAC,EAAE,EAAE;YAC3B,OAAO;gBACL,UAAU;gBACV,WAAW,CAAC,eAAe,CAAC,UAAU,EAAE,UAAU,CAAC;aACpD,CAAC;QACJ,CAAC,CACF,CAAC;QAEF,OAAO,MAAM,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;IAC3C,CAAC;IAED,MAAM,CAAC,eAAe,CAIpB,UAAuB,EACvB,WAAoC;QAEpC,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,GAAG,CACpD,CAAC,CAAC,WAAW,EAAE,UAAU,CAAC,EAAE,EAAE;YAC5B,OAAO;gBACL,WAAW;gBACX;oBACE,UAAU;oBACV,WAAW;oBACX,UAAU;iBACX;aACF,CAAC;QACJ,CAAC,CACF,CAAC;QAEF,OAAO,MAAM,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC;IAC5C,CAAC;IAED,MAAM,CAAC,iBAAiB,
|
|
1
|
+
{"version":3,"file":"grpc.servers.js","sourceRoot":"","sources":["../../src/servers/grpc.servers.ts"],"names":[],"mappings":";;;AAQA,MAAa,WAAW;IACtB,MAAM,CAAC,MAAM,CACX,WAAmC;QAEnC,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,GAAG,CACnD,CAAC,CAAC,UAAU,EAAE,UAAU,CAAC,EAAE,EAAE;YAC3B,OAAO;gBACL,UAAU;gBACV,WAAW,CAAC,eAAe,CAAC,UAAU,EAAE,UAAU,CAAC;aACpD,CAAC;QACJ,CAAC,CACF,CAAC;QAEF,OAAO,MAAM,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;IAC3C,CAAC;IAED,MAAM,CAAC,eAAe,CAIpB,UAAuB,EACvB,WAAoC;QAEpC,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,GAAG,CACpD,CAAC,CAAC,WAAW,EAAE,UAAU,CAAC,EAAE,EAAE;YAC5B,OAAO;gBACL,WAAW;gBACX;oBACE,UAAU;oBACV,WAAW;oBACX,UAAU;iBACX;aACF,CAAC;QACJ,CAAC,CACF,CAAC;QAEF,OAAO,MAAM,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC;IAC5C,CAAC;IAED,MAAM,CAAC,iBAAiB,CAItB,MAAe;QACf,MAAM,WAAW,GAA2B,EAAE,CAAC;QAE/C,KAAK,MAAM,UAAU,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE;YAC9C,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE;gBAC7C,WAAW,CAAC,IAAI,CAAC,KAA6B,CAAC,CAAC;aACjD;SACF;QACD,OAAO,WAAW,CAAC;IACrB,CAAC;CACF;AArDD,kCAqDC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsdk/grpc.clients",
|
|
3
|
-
"version": "2.6.0-next.
|
|
3
|
+
"version": "2.6.0-next.14",
|
|
4
4
|
"description": "Grpc clients infrastructure",
|
|
5
5
|
"license": "Apache License 2.0",
|
|
6
6
|
"publishConfig": {
|
|
@@ -17,15 +17,16 @@
|
|
|
17
17
|
"@grpc/grpc-js": "^1.8.7",
|
|
18
18
|
"@nestjs/common": "^9.0.0",
|
|
19
19
|
"@nestjs/microservices": "^9.0.0",
|
|
20
|
-
"@rsdk/autodoc.protocol": "^2.6.0-next.
|
|
21
|
-
"@rsdk/
|
|
22
|
-
"@rsdk/
|
|
23
|
-
"@rsdk/
|
|
24
|
-
"@rsdk/
|
|
25
|
-
"@rsdk/
|
|
20
|
+
"@rsdk/autodoc.protocol": "^2.6.0-next.13",
|
|
21
|
+
"@rsdk/builtin-contract": "*",
|
|
22
|
+
"@rsdk/common": "^2.6.0-next.13",
|
|
23
|
+
"@rsdk/core": "^2.6.0-next.13",
|
|
24
|
+
"@rsdk/grpc.common": "^2.6.0-next.13",
|
|
25
|
+
"@rsdk/logging": "^2.6.0-next.13",
|
|
26
|
+
"@rsdk/metadata": "^2.6.0-next.13",
|
|
26
27
|
"nice-grpc": "^2.1.4",
|
|
27
28
|
"nice-grpc-opentelemetry": "^0.1.2",
|
|
28
29
|
"rxjs": "^7.0.0"
|
|
29
30
|
},
|
|
30
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "d233dca2ccb88a31a2bb23990fe78553122e6166"
|
|
31
32
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Status } from '@rsdk/builtin-contract/dist/grpc/error/v1/error';
|
|
1
2
|
import {
|
|
2
3
|
AuthException,
|
|
3
4
|
ConflictException,
|
|
@@ -8,7 +9,7 @@ import {
|
|
|
8
9
|
NotFoundException,
|
|
9
10
|
TimeoutException,
|
|
10
11
|
} from '@rsdk/core';
|
|
11
|
-
import { ClientError, Status } from 'nice-grpc';
|
|
12
|
+
import { ClientError, Status as NiceGrpcStatus } from 'nice-grpc';
|
|
12
13
|
import type { ClientMiddleware } from 'nice-grpc-common';
|
|
13
14
|
|
|
14
15
|
/**
|
|
@@ -17,8 +18,25 @@ import type { ClientMiddleware } from 'nice-grpc-common';
|
|
|
17
18
|
export const exceptionMapperMiddleware = (): ClientMiddleware =>
|
|
18
19
|
// eslint-disable-next-line unicorn/consistent-function-scoping
|
|
19
20
|
async function* (call, options) {
|
|
21
|
+
let status: Status | undefined;
|
|
22
|
+
|
|
20
23
|
try {
|
|
21
|
-
return yield* call.next(call.request,
|
|
24
|
+
return yield* call.next(call.request, {
|
|
25
|
+
...options,
|
|
26
|
+
/**
|
|
27
|
+
* @link https://github.com/deeplay-io/nice-grpc/blob/2d781a477911b1d8a4a7b2faae27c7374ade8076/packages/nice-grpc-error-details/src/client/errorDetailsClientMiddleware.ts#L13
|
|
28
|
+
* @param trailer
|
|
29
|
+
*/
|
|
30
|
+
onTrailer(trailer) {
|
|
31
|
+
const detailsBuffer = trailer.get('grpc-status-details-bin');
|
|
32
|
+
|
|
33
|
+
if (detailsBuffer != null) {
|
|
34
|
+
status = Status.decode(detailsBuffer);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
options.onTrailer?.(trailer);
|
|
38
|
+
},
|
|
39
|
+
});
|
|
22
40
|
} catch (error: unknown) {
|
|
23
41
|
if (!(error instanceof ClientError)) {
|
|
24
42
|
throw new InternalException('GRPC call failed with unknown error', {
|
|
@@ -42,29 +60,40 @@ export const exceptionMapperMiddleware = (): ClientMiddleware =>
|
|
|
42
60
|
path: error.path,
|
|
43
61
|
|
|
44
62
|
/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
63
|
+
* A developer-facing error message, which should be in English. Any
|
|
64
|
+
* user-facing error message should be localized and sent in the
|
|
65
|
+
* [google.rpc.Status.details][google.rpc.Status.details] field, or localized by the client.
|
|
66
|
+
*
|
|
67
|
+
* https://github.com/deeplay-io/nice-grpc/blob/f0db4d130e1243db1cecb6586dca679e5d9b8fd5/packages/nice-grpc-error-details/proto/google/rpc/status.proto#L39
|
|
47
68
|
*/
|
|
69
|
+
statusMessage: status?.message,
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* any context from call
|
|
73
|
+
*/
|
|
74
|
+
details: status?.details,
|
|
48
75
|
},
|
|
49
76
|
};
|
|
50
77
|
|
|
51
78
|
/**
|
|
52
79
|
* According to /docs/images/exceptions.mapping.png
|
|
53
80
|
*/
|
|
81
|
+
|
|
82
|
+
// TODO: maybe replace to map and `Reflect.construct`
|
|
54
83
|
switch (error.code) {
|
|
55
|
-
case
|
|
84
|
+
case NiceGrpcStatus.DEADLINE_EXCEEDED:
|
|
56
85
|
throw new TimeoutException(message, props);
|
|
57
|
-
case
|
|
86
|
+
case NiceGrpcStatus.INVALID_ARGUMENT:
|
|
58
87
|
throw new InputException(message, props);
|
|
59
|
-
case
|
|
88
|
+
case NiceGrpcStatus.ALREADY_EXISTS:
|
|
60
89
|
throw new DuplicateEntityException(message, props);
|
|
61
|
-
case
|
|
90
|
+
case NiceGrpcStatus.FAILED_PRECONDITION:
|
|
62
91
|
throw new ConflictException(message, props);
|
|
63
|
-
case
|
|
92
|
+
case NiceGrpcStatus.UNAUTHENTICATED:
|
|
64
93
|
throw new AuthException(message, props);
|
|
65
|
-
case
|
|
94
|
+
case NiceGrpcStatus.PERMISSION_DENIED:
|
|
66
95
|
throw new NotAllowedException(message, props);
|
|
67
|
-
case
|
|
96
|
+
case NiceGrpcStatus.NOT_FOUND:
|
|
68
97
|
throw new NotFoundException(message, props);
|
|
69
98
|
default:
|
|
70
99
|
throw new InternalException(message, props);
|
|
@@ -47,7 +47,8 @@ export class GrpcServers {
|
|
|
47
47
|
|
|
48
48
|
static extractDefinition<
|
|
49
49
|
TKeyDeclaration extends GrpcServerDeclaration,
|
|
50
|
-
TKeyMap extends
|
|
50
|
+
TKeyMap extends
|
|
51
|
+
GrpcServerMap<TKeyDeclaration> = GrpcServerMap<TKeyDeclaration>,
|
|
51
52
|
>(keyMap: TKeyMap): GrpcServerDefinition[] {
|
|
52
53
|
const definitions: GrpcServerDefinition[] = [];
|
|
53
54
|
|