@xrystal/core 3.23.7 → 3.23.8
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
|
@@ -20,18 +20,16 @@ export class BaseController {
|
|
|
20
20
|
const ctx = store?.ctx || {};
|
|
21
21
|
const req = store?.req || {};
|
|
22
22
|
const identityT = (k) => k;
|
|
23
|
-
const body = ctx.body || req.body || {};
|
|
23
|
+
const body = ctx.body || req.body || ctx.request?.body || {};
|
|
24
24
|
let query = ctx.query || req.query || {};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
query = qs.parse(urlStr.split('?')[1]);
|
|
29
|
-
}
|
|
25
|
+
const urlStr = ctx.url || req.url || ctx.request?.url || '';
|
|
26
|
+
if (Object.keys(query).length === 0 && typeof urlStr === 'string' && urlStr.includes('?')) {
|
|
27
|
+
query = qs.parse(urlStr.split('?')[1]);
|
|
30
28
|
}
|
|
31
29
|
const params = ctx.params || req.params || {};
|
|
32
30
|
const headers = ctx.headers || req.headers || ctx.request?.headers || {};
|
|
33
31
|
return {
|
|
34
|
-
url:
|
|
32
|
+
url: urlStr,
|
|
35
33
|
method: ctx.method || req.method || ctx.request?.method || '',
|
|
36
34
|
headers,
|
|
37
35
|
body,
|
|
@@ -128,10 +126,18 @@ export default class Controller extends BaseController {
|
|
|
128
126
|
if (checkResult !== true) {
|
|
129
127
|
const code = checkResult?.code || 400;
|
|
130
128
|
const msg = checkResult?.message || (typeof checkResult === 'string' ? checkResult : 'error_validation');
|
|
129
|
+
let errorPayload = undefined;
|
|
130
|
+
if (checkResult?.payload) {
|
|
131
|
+
errorPayload = {
|
|
132
|
+
data: checkResult.payload.data ?? checkResult.payload,
|
|
133
|
+
extraData: checkResult.payload.extraData ?? {}
|
|
134
|
+
};
|
|
135
|
+
}
|
|
131
136
|
return currentRes.status(code).send(new ResponseSchema({
|
|
132
137
|
status: false,
|
|
133
138
|
message: this.parseMessage(msg, currentReq.t, true),
|
|
134
|
-
code
|
|
139
|
+
code,
|
|
140
|
+
payload: errorPayload
|
|
135
141
|
}).getResponse);
|
|
136
142
|
}
|
|
137
143
|
}
|
|
@@ -170,10 +176,9 @@ export default class Controller extends BaseController {
|
|
|
170
176
|
finalExtraData = obj.extraData;
|
|
171
177
|
}
|
|
172
178
|
else {
|
|
173
|
-
const
|
|
174
|
-
if (!
|
|
179
|
+
const hasMeta = obj.status !== undefined || obj.message !== undefined || obj.code !== undefined;
|
|
180
|
+
if (!hasMeta && Object.keys(obj).length > 0)
|
|
175
181
|
finalData = obj;
|
|
176
|
-
}
|
|
177
182
|
}
|
|
178
183
|
if (obj.message)
|
|
179
184
|
messageSource = obj.message;
|