@yolo-croket-dev/core 1.9.13-beta.1 → 1.9.13
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
CHANGED
|
@@ -17,18 +17,11 @@ class HttpExceptionCustom extends common_1.HttpException {
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
exports.HttpExceptionCustom = HttpExceptionCustom;
|
|
20
|
-
function resolveAmqpTimeout(timeoutMs) {
|
|
21
|
-
if (typeof timeoutMs !== 'number' || !Number.isFinite(timeoutMs) || timeoutMs <= 0) {
|
|
22
|
-
return DEFAULT_TIMEOUT;
|
|
23
|
-
}
|
|
24
|
-
return Math.min(timeoutMs, DEFAULT_TIMEOUT);
|
|
25
|
-
}
|
|
26
20
|
async function AmqpHandler(client, messagePattern, payload) {
|
|
27
|
-
var _a, _b, _c, _d
|
|
21
|
+
var _a, _b, _c, _d;
|
|
28
22
|
let data;
|
|
29
|
-
const timeoutMs = resolveAmqpTimeout((_a = payload === null || payload === void 0 ? void 0 : payload.param) === null || _a === void 0 ? void 0 : _a.timeout);
|
|
30
23
|
try {
|
|
31
|
-
data = await (0, rxjs_1.lastValueFrom)(client.send(messagePattern, payload).pipe((0, operators_1.timeout)(
|
|
24
|
+
data = await (0, rxjs_1.lastValueFrom)(client.send(messagePattern, payload).pipe((0, operators_1.timeout)(DEFAULT_TIMEOUT)));
|
|
32
25
|
if (data.isError) {
|
|
33
26
|
const status = data.status || 500;
|
|
34
27
|
const subMessage = data.subMessage;
|
|
@@ -36,7 +29,7 @@ async function AmqpHandler(client, messagePattern, payload) {
|
|
|
36
29
|
* 파일 객체 처리
|
|
37
30
|
* 다른 서비스에서 이미 처리가 될 수 있음
|
|
38
31
|
* */
|
|
39
|
-
(0, _1.reWriteFileValue)((
|
|
32
|
+
(0, _1.reWriteFileValue)((_a = data === null || data === void 0 ? void 0 : data.arg) === null || _a === void 0 ? void 0 : _a.file);
|
|
40
33
|
const errInfo = data.errInfo ? data.errInfo : {
|
|
41
34
|
message: data.errMessage,
|
|
42
35
|
type: data.errType,
|
|
@@ -57,7 +50,7 @@ async function AmqpHandler(client, messagePattern, payload) {
|
|
|
57
50
|
catch (err) {
|
|
58
51
|
if (typeof err === 'string' && err.includes('There is no matching message handler defined in the remote service.')) {
|
|
59
52
|
msaLogger.error('NOT_EXISTS_MESSAGE_PATTERN', {
|
|
60
|
-
traceId: ((
|
|
53
|
+
traceId: ((_b = payload === null || payload === void 0 ? void 0 : payload.param) === null || _b === void 0 ? void 0 : _b.traceId) || '-',
|
|
61
54
|
errInfo: {
|
|
62
55
|
errType: 'NOT_EXISTS_MESSAGE_PATTERN',
|
|
63
56
|
message: `${messagePattern} 해당 메시지 패턴은 존재하지 않습니다.`,
|
|
@@ -71,7 +64,7 @@ async function AmqpHandler(client, messagePattern, payload) {
|
|
|
71
64
|
}
|
|
72
65
|
else if (err instanceof rxjs_1.TimeoutError || err.message === DEFAULT_TIMEOUT_MESSAGE) {
|
|
73
66
|
msaLogger.error('TIMEOUT_ERROR', {
|
|
74
|
-
traceId: ((
|
|
67
|
+
traceId: ((_c = payload === null || payload === void 0 ? void 0 : payload.param) === null || _c === void 0 ? void 0 : _c.traceId) || '-',
|
|
75
68
|
errInfo: {
|
|
76
69
|
errType: 'TIMEOUT_ERROR',
|
|
77
70
|
message: DEFAULT_TIMEOUT_MESSAGE,
|
|
@@ -84,7 +77,7 @@ async function AmqpHandler(client, messagePattern, payload) {
|
|
|
84
77
|
});
|
|
85
78
|
}
|
|
86
79
|
else {
|
|
87
|
-
msaLogger.warn('AMQP_HANDLER_ERROR', { traceId: ((
|
|
80
|
+
msaLogger.warn('AMQP_HANDLER_ERROR', { traceId: ((_d = payload === null || payload === void 0 ? void 0 : payload.param) === null || _d === void 0 ? void 0 : _d.traceId) || '-' }, { err });
|
|
88
81
|
throw err;
|
|
89
82
|
}
|
|
90
83
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yolo-croket-dev/core",
|
|
3
|
-
"version": "1.9.13
|
|
3
|
+
"version": "1.9.13",
|
|
4
4
|
"author": "Yolo Co., Ltd.",
|
|
5
5
|
"description": "Yolo commonization module",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc",
|
|
9
9
|
"lint": "eslint src/**/*.ts",
|
|
10
|
-
"test": "yarn build && node --test tests
|
|
10
|
+
"test": "yarn build && node --test tests/graceful-shutdown-rmq.test.cjs",
|
|
11
11
|
"fix": "eslint --fix src/**/*.ts",
|
|
12
12
|
"clean": "tsc --build --clean",
|
|
13
13
|
"prepublishOnly": "npm run build",
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
const assert = require('node:assert/strict');
|
|
2
|
-
const test = require('node:test');
|
|
3
|
-
const { Observable } = require('rxjs');
|
|
4
|
-
|
|
5
|
-
const { AmqpHandler, HttpExceptionCustom } = require('../functions/amqp-handler.function.js');
|
|
6
|
-
|
|
7
|
-
test('param.timeout이 지나면 AMQP Observable 구독을 해제한다', async () => {
|
|
8
|
-
let isUnsubscribed = false;
|
|
9
|
-
const client = {
|
|
10
|
-
send() {
|
|
11
|
-
return new Observable(() => () => {
|
|
12
|
-
isUnsubscribed = true;
|
|
13
|
-
});
|
|
14
|
-
},
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
await assert.rejects(
|
|
18
|
-
AmqpHandler(client, 'test.timeout', {
|
|
19
|
-
payload: {},
|
|
20
|
-
param: {
|
|
21
|
-
traceId: 'trace-id',
|
|
22
|
-
timeout: 5,
|
|
23
|
-
},
|
|
24
|
-
}),
|
|
25
|
-
(error) => {
|
|
26
|
-
assert.equal(error instanceof HttpExceptionCustom, true);
|
|
27
|
-
assert.equal(error.errInfo.type, 'TIMEOUT_ERROR');
|
|
28
|
-
return true;
|
|
29
|
-
},
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
assert.equal(isUnsubscribed, true);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
test('응답이 먼저 완료되면 기존 AMQP 응답을 반환한다', async () => {
|
|
36
|
-
const client = {
|
|
37
|
-
send() {
|
|
38
|
-
return new Observable((subscriber) => {
|
|
39
|
-
subscriber.next({ isError: false, data: { ok: true } });
|
|
40
|
-
subscriber.complete();
|
|
41
|
-
});
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const result = await AmqpHandler(client, 'test.success', { payload: {}, param: { traceId: 'trace-id', timeout: 50 } });
|
|
46
|
-
assert.deepEqual(result, { data: { ok: true } });
|
|
47
|
-
});
|