@xrystal/core 3.24.1 → 3.24.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/package.json
CHANGED
|
@@ -93,28 +93,34 @@ export default class Controller extends BaseController {
|
|
|
93
93
|
this.supportedProtocols = Array.isArray(protocols) ? protocols : [protocols || ProtocolEnum.HTTP];
|
|
94
94
|
}
|
|
95
95
|
parseMessage(msg, t, isError = false) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
let
|
|
99
|
-
let useDirect = false;
|
|
96
|
+
const content = String(msg || (isError ? 'unsuccessful' : 'success_process'));
|
|
97
|
+
let method = isError ? 'unsuccessful' : 'successfully';
|
|
98
|
+
let payloadString = content;
|
|
100
99
|
if (content.startsWith('@')) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
100
|
+
const firstSpace = content.indexOf(' ');
|
|
101
|
+
if (firstSpace !== -1) {
|
|
102
|
+
method = content.substring(1, firstSpace);
|
|
103
|
+
payloadString = content.substring(firstSpace + 1);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
method = content.substring(1);
|
|
107
|
+
payloadString = '';
|
|
108
|
+
}
|
|
109
109
|
}
|
|
110
|
-
|
|
111
|
-
|
|
110
|
+
const params = payloadString.split('-').map(p => p.trim()).filter(p => p !== '');
|
|
111
|
+
const p1Raw = params[0] || '';
|
|
112
|
+
const p1 = (p1Raw === method || p1Raw === 'unsuccessful' || p1Raw === 'success_process') ? '' : t(p1Raw);
|
|
113
|
+
const p2 = params.slice(1).map(v => t(v)).join(' ');
|
|
114
|
+
if (responseMessageHelper[method]) {
|
|
115
|
+
return responseMessageHelper[method](p1, p2, t);
|
|
112
116
|
}
|
|
113
|
-
return
|
|
117
|
+
return isError
|
|
118
|
+
? responseMessageHelper.unsuccessful(p1, p2, t)
|
|
119
|
+
: responseMessageHelper.successfully(p1, p2, t);
|
|
114
120
|
}
|
|
115
121
|
async schema({ checks, logic, response }) {
|
|
122
|
+
let currentReq = this.req;
|
|
116
123
|
try {
|
|
117
|
-
const currentReq = this.req;
|
|
118
124
|
const currentRes = this.res;
|
|
119
125
|
const p = {
|
|
120
126
|
req: currentReq,
|
|
@@ -129,7 +135,7 @@ export default class Controller extends BaseController {
|
|
|
129
135
|
const checkResult = await checks(p);
|
|
130
136
|
if (checkResult !== true) {
|
|
131
137
|
const bizCode = checkResult?.code ?? 400;
|
|
132
|
-
const msg = checkResult?.message ||
|
|
138
|
+
const msg = checkResult?.message || checkResult;
|
|
133
139
|
let errorPayload = undefined;
|
|
134
140
|
if (checkResult?.payload) {
|
|
135
141
|
errorPayload = {
|
|
@@ -154,10 +160,9 @@ export default class Controller extends BaseController {
|
|
|
154
160
|
}
|
|
155
161
|
if (logicResult?.status === false) {
|
|
156
162
|
const bizCode = logicResult.code ?? 400;
|
|
157
|
-
const msg = logicResult.message || 'unsuccessful';
|
|
158
163
|
return currentRes.status(bizCode).send(new ResponseSchema({
|
|
159
164
|
status: false,
|
|
160
|
-
message: this.parseMessage(
|
|
165
|
+
message: this.parseMessage(logicResult.message, currentReq.t, true),
|
|
161
166
|
code: bizCode
|
|
162
167
|
}).getResponse);
|
|
163
168
|
}
|
|
@@ -213,9 +218,10 @@ export default class Controller extends BaseController {
|
|
|
213
218
|
}
|
|
214
219
|
catch (error) {
|
|
215
220
|
this.logger?.log(LoggerLayerEnum.ERROR, `Controller Error: ${error.message}`);
|
|
221
|
+
const t = currentReq?.t || ((k) => k);
|
|
216
222
|
return this.res.status(500).send(new ResponseSchema({
|
|
217
223
|
status: false,
|
|
218
|
-
message: error.message
|
|
224
|
+
message: this.parseMessage(error.message, t, true),
|
|
219
225
|
code: 500
|
|
220
226
|
}).getResponse);
|
|
221
227
|
}
|