@rayondigital/nest-dapr 0.9.62 → 0.9.64
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.
|
@@ -14,6 +14,7 @@ const common_1 = require("@nestjs/common");
|
|
|
14
14
|
const dapr_context_service_1 = require("../dapr-context-service");
|
|
15
15
|
const actor_runtime_service_1 = require("./actor-runtime.service");
|
|
16
16
|
const client_cache_1 = require("./client-cache");
|
|
17
|
+
const serializable_error_1 = require("./serializable-error");
|
|
17
18
|
class ActorProxyBuilder {
|
|
18
19
|
constructor(moduleRef, actorTypeClass, ...args) {
|
|
19
20
|
this.moduleRef = moduleRef;
|
|
@@ -63,7 +64,11 @@ class ActorProxyBuilder {
|
|
|
63
64
|
return __awaiter(this, void 0, void 0, function* () {
|
|
64
65
|
const actorManager = this.actorRuntimeService.getActorManager(actorTypeClassName);
|
|
65
66
|
const requestBody = JSON.stringify(args);
|
|
66
|
-
|
|
67
|
+
const result = yield actorManager.invoke(actorId, methodName, Buffer.from(requestBody));
|
|
68
|
+
if (serializable_error_1.SerializableError.isSerializableError(result)) {
|
|
69
|
+
throw serializable_error_1.SerializableError.fromJSON(result);
|
|
70
|
+
}
|
|
71
|
+
return result;
|
|
67
72
|
});
|
|
68
73
|
}
|
|
69
74
|
callExternalActorMethod(actorTypeClassName, actorId, methodName, args) {
|
|
@@ -75,7 +80,14 @@ class ActorProxyBuilder {
|
|
|
75
80
|
const correlationId = this.daprContextService.getCorrelationId(true);
|
|
76
81
|
const traceId = this.daprContextService.getTraceId(true);
|
|
77
82
|
const body = yield this.prepareBody(this.daprContextService, args, originalBody);
|
|
78
|
-
|
|
83
|
+
const result = yield this.actorClient.actor.invoke(actorTypeClassName, actorId, methodName, body, correlationId, traceId);
|
|
84
|
+
if (serializable_error_1.SerializableError.isSerializableError(result)) {
|
|
85
|
+
const error = serializable_error_1.SerializableError.fromJSON(result);
|
|
86
|
+
error.correlationId = correlationId;
|
|
87
|
+
error.traceId = traceId;
|
|
88
|
+
throw error;
|
|
89
|
+
}
|
|
90
|
+
return result;
|
|
79
91
|
});
|
|
80
92
|
}
|
|
81
93
|
prepareBody(daprContextService, args, body) {
|
|
@@ -161,10 +161,10 @@ let NestActorManager = NestActorManager_1 = class NestActorManager {
|
|
|
161
161
|
actor_1.default.prototype.handlerMethod = function (req, res) {
|
|
162
162
|
var _a;
|
|
163
163
|
return __awaiter(this, void 0, void 0, function* () {
|
|
164
|
-
const { actorTypeName, actorId, methodName } = req.params;
|
|
165
|
-
const body = req.body;
|
|
166
|
-
const dataSerialized = this.serializer.serialize(body);
|
|
167
164
|
try {
|
|
165
|
+
const { actorTypeName, actorId, methodName } = req.params;
|
|
166
|
+
const body = req.body;
|
|
167
|
+
const dataSerialized = this.serializer.serialize(body);
|
|
168
168
|
const result = yield ActorRuntime_1.default.getInstance(this.client.daprClient).invoke(actorTypeName, actorId, methodName, dataSerialized);
|
|
169
169
|
res.statusCode = HttpStatusCode_enum_1.default.OK;
|
|
170
170
|
return this.handleResult(res, result);
|
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
export declare class SerializableError extends Error {
|
|
2
2
|
statusCode: number;
|
|
3
|
+
$type: string;
|
|
4
|
+
correlationId?: string;
|
|
5
|
+
traceId?: string;
|
|
3
6
|
constructor(message: string, statusCode?: number);
|
|
4
7
|
toJSON(): {
|
|
5
8
|
name: string;
|
|
6
9
|
message: string;
|
|
7
10
|
statusCode: number;
|
|
11
|
+
correlationId: string;
|
|
12
|
+
traceId: string;
|
|
13
|
+
stack: string;
|
|
14
|
+
$type: string;
|
|
8
15
|
};
|
|
16
|
+
static fromJSON(json: any): SerializableError;
|
|
17
|
+
static isSerializableError(error: any): error is SerializableError;
|
|
9
18
|
}
|
|
@@ -1,17 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SerializableError = void 0;
|
|
4
|
+
const serializableErrorTypeName = 'SerializableError';
|
|
4
5
|
class SerializableError extends Error {
|
|
5
6
|
constructor(message, statusCode = 400) {
|
|
6
7
|
super(message);
|
|
7
8
|
this.statusCode = statusCode;
|
|
9
|
+
this.$type = serializableErrorTypeName;
|
|
8
10
|
}
|
|
9
11
|
toJSON() {
|
|
12
|
+
if (!this.stack) {
|
|
13
|
+
Error.captureStackTrace(this, SerializableError);
|
|
14
|
+
}
|
|
10
15
|
return {
|
|
11
16
|
name: this.name,
|
|
12
17
|
message: this.message,
|
|
13
18
|
statusCode: this.statusCode,
|
|
19
|
+
correlationId: this.correlationId,
|
|
20
|
+
traceId: this.traceId,
|
|
21
|
+
stack: this.stack,
|
|
22
|
+
$type: serializableErrorTypeName,
|
|
14
23
|
};
|
|
15
24
|
}
|
|
25
|
+
static fromJSON(json) {
|
|
26
|
+
var _a;
|
|
27
|
+
const error = new SerializableError(json.message, json.statusCode);
|
|
28
|
+
error.$type = (_a = json.$type) !== null && _a !== void 0 ? _a : serializableErrorTypeName;
|
|
29
|
+
error.correlationId = json.correlationId;
|
|
30
|
+
error.traceId = json.traceId;
|
|
31
|
+
error.stack = json.stack;
|
|
32
|
+
error.name = json.name;
|
|
33
|
+
return error;
|
|
34
|
+
}
|
|
35
|
+
static isSerializableError(error) {
|
|
36
|
+
if (error instanceof SerializableError) {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
return error && error.$type === 'SerializableError';
|
|
40
|
+
}
|
|
16
41
|
}
|
|
17
42
|
exports.SerializableError = SerializableError;
|
package/package.json
CHANGED