@nmxjs/api 1.3.1 → 1.3.3
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/ApiService/services/CreateApiService.js +1 -4
- package/dist/ApiService/services/CreateApiService.js.map +1 -1
- package/dist/ApiService/utils/index.d.ts +1 -1
- package/dist/ApiService/utils/index.js +1 -1
- package/dist/ApiService/utils/index.js.map +1 -1
- package/dist/ApiService/utils/parseRpcError.d.ts +1 -0
- package/dist/ApiService/utils/{parseGrpcError.js → parseRpcError.js} +11 -7
- package/dist/ApiService/utils/parseRpcError.js.map +1 -0
- package/package.json +1 -1
- package/tests/ApiService/utils/parseRpcError.spec.ts +120 -0
- package/dist/ApiService/utils/parseGrpcError.d.ts +0 -1
- package/dist/ApiService/utils/parseGrpcError.js.map +0 -1
- package/tests/ApiService/utils/parseGrpcError.spec.ts +0 -80
|
@@ -65,10 +65,7 @@ let CreateApiService = class CreateApiService {
|
|
|
65
65
|
if ((_a = e.message) === null || _a === void 0 ? void 0 : _a.includes('Empty response. There are no subscribers listening to that message')) {
|
|
66
66
|
throw new errors_1.ServiceNotAvailableError(serviceName, methodName);
|
|
67
67
|
}
|
|
68
|
-
|
|
69
|
-
throw (0, utils_1.parseGrpcError)(e);
|
|
70
|
-
}
|
|
71
|
-
throw e;
|
|
68
|
+
throw (0, utils_1.parseRpcError)(e);
|
|
72
69
|
});
|
|
73
70
|
return (0, utils_1.transformParseJson)(`${route}.response`, result);
|
|
74
71
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CreateApiService.js","sourceRoot":"","sources":["../../../src/ApiService/services/CreateApiService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wCAAwC;AACxC,uCAAuC;AACvC,2CAAoD;AACpD,0CAAmD;AACnD,+BAAmD;AACnD,0CAAyD;AACzD,4CAAoE;AAEpE,mEAAgE;AAChE,
|
|
1
|
+
{"version":3,"file":"CreateAp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AAM,EAAE,CAAC;oBACZ,MAAM,GAAG,MAAM,OAAO,EAAE,CAAC;oBACzB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC,CAAC;gBAClG,CAAC;gBAED,OAAO,MAAM,CAAC;YAChB,CAAC,CAAC;YAEF,IAAI,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,UAAU,EAAE,CAAC;gBAC1C,OAAO,CAAC,cAAc,CAAC,0BAAc,EAAE,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,UAAU,EAAE,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC;YACjG,CAAC;YAED,OAAO,GAAG,CAAC;QACb,CAAC,EAAE,EAAE,CAAC,CAAC;QAEP,uCACK,MAAM,KACT,OAAO,IACP;IACJ,CAAC;CACF,CAAA;AA/EY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,mBAAU,GAAE;IAKR,WAAA,IAAA,eAAM,EAAC,kBAAS,CAAC,CAAA;IACjB,WAAA,IAAA,eAAM,EAAC,gCAAoB,CAAC,CAAA;qDACa,6CAAqB;GANtD,gBAAgB,CA+E5B"}
|
|
@@ -16,7 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./getJsonFieldsKeys"), exports);
|
|
18
18
|
__exportStar(require("./getQueryMutationByName"), exports);
|
|
19
|
-
__exportStar(require("./
|
|
19
|
+
__exportStar(require("./parseRpcError"), exports);
|
|
20
20
|
__exportStar(require("./transformParseJson"), exports);
|
|
21
21
|
__exportStar(require("./transformStringifyJson"), exports);
|
|
22
22
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/ApiService/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sDAAoC;AACpC,2DAAyC;AACzC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/ApiService/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sDAAoC;AACpC,2DAAyC;AACzC,kDAAgC;AAChC,uDAAqC;AACrC,2DAAyC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function parseRpcError(e: any): Error;
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.parseRpcError = void 0;
|
|
4
4
|
const constants_1 = require("../../ApiRouterCore/constants");
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
const
|
|
5
|
+
function parseRpcError(e) {
|
|
6
|
+
var _a, _b;
|
|
7
|
+
const raw = (_b = (_a = e.details) !== null && _a !== void 0 ? _a : e.message) !== null && _b !== void 0 ? _b : '';
|
|
8
|
+
if (!raw.includes(constants_1.endErrorText)) {
|
|
9
|
+
return e;
|
|
10
|
+
}
|
|
11
|
+
const cleanDetails = raw.split(constants_1.endErrorText)[0];
|
|
8
12
|
try {
|
|
9
13
|
const parsed = JSON.parse(cleanDetails);
|
|
10
14
|
const error = new Error(parsed.message || cleanDetails);
|
|
@@ -16,10 +20,10 @@ function parseGrpcError(e) {
|
|
|
16
20
|
}
|
|
17
21
|
catch (parseError) {
|
|
18
22
|
if (parseError instanceof SyntaxError) {
|
|
19
|
-
return
|
|
23
|
+
return e;
|
|
20
24
|
}
|
|
21
25
|
throw parseError;
|
|
22
26
|
}
|
|
23
27
|
}
|
|
24
|
-
exports.
|
|
25
|
-
//# sourceMappingURL=
|
|
28
|
+
exports.parseRpcError = parseRpcError;
|
|
29
|
+
//# sourceMappingURL=parseRpcError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parseRpcError.js","sourceRoot":"","sources":["../../../src/ApiService/utils/parseRpcError.ts"],"names":[],"mappings":";;;AAAA,6DAA6D;AAE7D,SAAgB,aAAa,CAAC,CAAM;;IAClC,MAAM,GAAG,GAAW,MAAA,MAAA,CAAC,CAAC,OAAO,mCAAI,CAAC,CAAC,OAAO,mCAAI,EAAE,CAAC;IAEjD,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,wBAAY,CAAC,EAAE,CAAC;QAChC,OAAO,CAAC,CAAC;IACX,CAAC;IAED,MAAM,YAAY,GAAG,GAAG,CAAC,KAAK,CAAC,wBAAY,CAAC,CAAC,CAAC,CAAC,CAAC;IAEhD,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;QACxC,MAAM,KAAK,GAAQ,IAAI,KAAK,CAAC,MAAM,CAAC,OAAO,IAAI,YAAY,CAAC,CAAC;QAC7D,IAAI,MAAM,CAAC,IAAI;YAAE,KAAK,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;QAC1C,IAAI,MAAM,CAAC,UAAU;YAAE,KAAK,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;QAC5D,OAAO,KAAK,CAAC;IACf,CAAC;IAAC,OAAO,UAAU,EAAE,CAAC;QACpB,IAAI,UAAU,YAAY,WAAW,EAAE,CAAC;YACtC,OAAO,CAAC,CAAC;QACX,CAAC;QACD,MAAM,UAAU,CAAC;IACnB,CAAC;AACH,CAAC;AArBD,sCAqBC"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { parseRpcError } from '../../../src/ApiService/utils/parseRpcError';
|
|
2
|
+
import { endErrorText } from '../../../src/ApiRouterCore/constants/endErrorText';
|
|
3
|
+
|
|
4
|
+
describe('parseRpcError', () => {
|
|
5
|
+
it('should parse JSON details with message, code and statusCode', () => {
|
|
6
|
+
const payload = JSON.stringify({ message: 'Validation failed', code: 'VALIDATION_ERROR', statusCode: 400 });
|
|
7
|
+
const grpcError = { details: `${payload}${endErrorText}` };
|
|
8
|
+
const result: any = parseRpcError(grpcError);
|
|
9
|
+
|
|
10
|
+
expect(result.message).toBe('Validation failed');
|
|
11
|
+
expect(result.code).toBe('VALIDATION_ERROR');
|
|
12
|
+
expect(result.statusCode).toBe(400);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('should parse JSON details with only message', () => {
|
|
16
|
+
const payload = JSON.stringify({ message: 'Something broke' });
|
|
17
|
+
const grpcError = { details: `${payload}${endErrorText}` };
|
|
18
|
+
const result = parseRpcError(grpcError);
|
|
19
|
+
|
|
20
|
+
expect(result.message).toBe('Something broke');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('should handle plain text details (not JSON)', () => {
|
|
24
|
+
const grpcError = { details: `Plain error text${endErrorText}` };
|
|
25
|
+
const result = parseRpcError(grpcError);
|
|
26
|
+
|
|
27
|
+
expect(result).toBe(grpcError);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('should handle details without endErrorText marker', () => {
|
|
31
|
+
const payload = JSON.stringify({ message: 'Error without marker', code: 'ERR' });
|
|
32
|
+
const grpcError = { details: payload };
|
|
33
|
+
const result: any = parseRpcError(grpcError);
|
|
34
|
+
|
|
35
|
+
expect(result).toBe(grpcError);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('should fallback to details as message when JSON has no message field', () => {
|
|
39
|
+
const payload = JSON.stringify({ code: 'UNKNOWN' });
|
|
40
|
+
const grpcError = { details: `${payload}${endErrorText}` };
|
|
41
|
+
const result = parseRpcError(grpcError);
|
|
42
|
+
|
|
43
|
+
expect(result.message).toBe(payload);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('should not set code if not present in parsed JSON', () => {
|
|
47
|
+
const payload = JSON.stringify({ message: 'No code error' });
|
|
48
|
+
const grpcError = { details: `${payload}${endErrorText}` };
|
|
49
|
+
const result: any = parseRpcError(grpcError);
|
|
50
|
+
|
|
51
|
+
expect(result.message).toBe('No code error');
|
|
52
|
+
expect(result.code).toBeUndefined();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('should not set statusCode if not present in parsed JSON', () => {
|
|
56
|
+
const payload = JSON.stringify({ message: 'No status error' });
|
|
57
|
+
const grpcError = { details: `${payload}${endErrorText}` };
|
|
58
|
+
const result: any = parseRpcError(grpcError);
|
|
59
|
+
|
|
60
|
+
expect(result.statusCode).toBeUndefined();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('should handle cascade errors (multiple endErrorText markers)', () => {
|
|
64
|
+
const payload = JSON.stringify({ message: 'Original cascade error', code: 'CASCADE' });
|
|
65
|
+
const grpcError = { details: `${payload}${endErrorText}${endErrorText}` };
|
|
66
|
+
const result: any = parseRpcError(grpcError);
|
|
67
|
+
|
|
68
|
+
expect(result.message).toBe('Original cascade error');
|
|
69
|
+
expect(result.code).toBe('CASCADE');
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('should return original error when no endErrorText marker', () => {
|
|
73
|
+
const payload = JSON.stringify({ message: 'test' });
|
|
74
|
+
const grpcError = { details: payload };
|
|
75
|
+
const result = parseRpcError(grpcError);
|
|
76
|
+
|
|
77
|
+
expect(result).toBe(grpcError);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('should parse error.message when details is absent (NATS/TCP)', () => {
|
|
81
|
+
const payload = JSON.stringify({ message: 'Invalid credentials!', code: 'INVALID_CREDENTIALS_ERROR', statusCode: 401 });
|
|
82
|
+
const error = new Error(`${payload}${endErrorText}`);
|
|
83
|
+
const result: any = parseRpcError(error);
|
|
84
|
+
|
|
85
|
+
expect(result.message).toBe('Invalid credentials!');
|
|
86
|
+
expect(result.code).toBe('INVALID_CREDENTIALS_ERROR');
|
|
87
|
+
expect(result.statusCode).toBe(401);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('should parse error.message with only message field (NATS/TCP)', () => {
|
|
91
|
+
const payload = JSON.stringify({ message: 'Something broke' });
|
|
92
|
+
const error = new Error(`${payload}${endErrorText}`);
|
|
93
|
+
const result: any = parseRpcError(error);
|
|
94
|
+
|
|
95
|
+
expect(result.message).toBe('Something broke');
|
|
96
|
+
expect(result.code).toBeUndefined();
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('should prefer details over message when both present', () => {
|
|
100
|
+
const payload = JSON.stringify({ message: 'From details', code: 'DETAILS' });
|
|
101
|
+
const error: any = new Error('from message');
|
|
102
|
+
error.details = `${payload}${endErrorText}`;
|
|
103
|
+
const result: any = parseRpcError(error);
|
|
104
|
+
|
|
105
|
+
expect(result.message).toBe('From details');
|
|
106
|
+
expect(result.code).toBe('DETAILS');
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('should preserve code and statusCode for non-RPC errors', () => {
|
|
110
|
+
const error: any = new Error('Invalid credentials!');
|
|
111
|
+
error.code = 'INVALID_CREDENTIALS_ERROR';
|
|
112
|
+
error.statusCode = 401;
|
|
113
|
+
const result: any = parseRpcError(error);
|
|
114
|
+
|
|
115
|
+
expect(result).toBe(error);
|
|
116
|
+
expect(result.message).toBe('Invalid credentials!');
|
|
117
|
+
expect(result.code).toBe('INVALID_CREDENTIALS_ERROR');
|
|
118
|
+
expect(result.statusCode).toBe(401);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function parseGrpcError(e: any): Error;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parseGrpcError.js","sourceRoot":"","sources":["../../../src/ApiService/utils/parseGrpcError.ts"],"names":[],"mappings":";;;AAAA,6DAA6D;AAE7D,SAAgB,cAAc,CAAC,CAAM;IACnC,MAAM,OAAO,GAAW,CAAC,CAAC,OAAO,CAAC;IAClC,MAAM,YAAY,GAAG,OAAO,CAAC,KAAK,CAAC,wBAAY,CAAC,CAAC,CAAC,CAAC,CAAC;IAEpD,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;QACxC,MAAM,KAAK,GAAQ,IAAI,KAAK,CAAC,MAAM,CAAC,OAAO,IAAI,YAAY,CAAC,CAAC;QAC7D,IAAI,MAAM,CAAC,IAAI;YAAE,KAAK,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;QAC1C,IAAI,MAAM,CAAC,UAAU;YAAE,KAAK,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;QAC5D,OAAO,KAAK,CAAC;IACf,CAAC;IAAC,OAAO,UAAU,EAAE,CAAC;QACpB,IAAI,UAAU,YAAY,WAAW,EAAE,CAAC;YACtC,OAAO,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC;QACjC,CAAC;QACD,MAAM,UAAU,CAAC;IACnB,CAAC;AACH,CAAC;AAhBD,wCAgBC"}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { parseGrpcError } from '../../../src/ApiService/utils/parseGrpcError';
|
|
2
|
-
import { endErrorText } from '../../../src/ApiRouterCore/constants/endErrorText';
|
|
3
|
-
|
|
4
|
-
describe('parseGrpcError', () => {
|
|
5
|
-
it('should parse JSON details with message, code and statusCode', () => {
|
|
6
|
-
const payload = JSON.stringify({ message: 'Validation failed', code: 'VALIDATION_ERROR', statusCode: 400 });
|
|
7
|
-
const grpcError = { details: `${payload}${endErrorText}` };
|
|
8
|
-
const result: any = parseGrpcError(grpcError);
|
|
9
|
-
|
|
10
|
-
expect(result.message).toBe('Validation failed');
|
|
11
|
-
expect(result.code).toBe('VALIDATION_ERROR');
|
|
12
|
-
expect(result.statusCode).toBe(400);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('should parse JSON details with only message', () => {
|
|
16
|
-
const payload = JSON.stringify({ message: 'Something broke' });
|
|
17
|
-
const grpcError = { details: `${payload}${endErrorText}` };
|
|
18
|
-
const result = parseGrpcError(grpcError);
|
|
19
|
-
|
|
20
|
-
expect(result.message).toBe('Something broke');
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('should handle plain text details (not JSON)', () => {
|
|
24
|
-
const grpcError = { details: `Plain error text${endErrorText}` };
|
|
25
|
-
const result = parseGrpcError(grpcError);
|
|
26
|
-
|
|
27
|
-
expect(result.message).toBe('Plain error text');
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('should handle details without endErrorText marker', () => {
|
|
31
|
-
const payload = JSON.stringify({ message: 'Error without marker', code: 'ERR' });
|
|
32
|
-
const grpcError = { details: payload };
|
|
33
|
-
const result: any = parseGrpcError(grpcError);
|
|
34
|
-
|
|
35
|
-
expect(result.message).toBe('Error without marker');
|
|
36
|
-
expect(result.code).toBe('ERR');
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('should fallback to details as message when JSON has no message field', () => {
|
|
40
|
-
const payload = JSON.stringify({ code: 'UNKNOWN' });
|
|
41
|
-
const grpcError = { details: `${payload}${endErrorText}` };
|
|
42
|
-
const result = parseGrpcError(grpcError);
|
|
43
|
-
|
|
44
|
-
expect(result.message).toBe(payload);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('should not set code if not present in parsed JSON', () => {
|
|
48
|
-
const payload = JSON.stringify({ message: 'No code error' });
|
|
49
|
-
const grpcError = { details: `${payload}${endErrorText}` };
|
|
50
|
-
const result: any = parseGrpcError(grpcError);
|
|
51
|
-
|
|
52
|
-
expect(result.message).toBe('No code error');
|
|
53
|
-
expect(result.code).toBeUndefined();
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('should not set statusCode if not present in parsed JSON', () => {
|
|
57
|
-
const payload = JSON.stringify({ message: 'No status error' });
|
|
58
|
-
const grpcError = { details: `${payload}${endErrorText}` };
|
|
59
|
-
const result: any = parseGrpcError(grpcError);
|
|
60
|
-
|
|
61
|
-
expect(result.statusCode).toBeUndefined();
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('should handle cascade errors (multiple endErrorText markers)', () => {
|
|
65
|
-
const payload = JSON.stringify({ message: 'Original cascade error', code: 'CASCADE' });
|
|
66
|
-
const grpcError = { details: `${payload}${endErrorText}${endErrorText}` };
|
|
67
|
-
const result: any = parseGrpcError(grpcError);
|
|
68
|
-
|
|
69
|
-
expect(result.message).toBe('Original cascade error');
|
|
70
|
-
expect(result.code).toBe('CASCADE');
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('should return Error instance', () => {
|
|
74
|
-
const payload = JSON.stringify({ message: 'test' });
|
|
75
|
-
const grpcError = { details: payload };
|
|
76
|
-
const result = parseGrpcError(grpcError);
|
|
77
|
-
|
|
78
|
-
expect(result).toBeInstanceOf(Error);
|
|
79
|
-
});
|
|
80
|
-
});
|