@xrystal/core 3.23.8 → 3.24.0
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
|
@@ -70,12 +70,13 @@ export class BaseController {
|
|
|
70
70
|
if (!contentType) {
|
|
71
71
|
contentType = isRaw ? 'application/octet-stream' : 'application/json';
|
|
72
72
|
}
|
|
73
|
-
|
|
73
|
+
let rawCode = store.metadata._code || 200;
|
|
74
|
+
let httpStatus = (rawCode >= 100 && rawCode <= 101) || (rawCode >= 200 && rawCode <= 599) ? rawCode : (rawCode === 0 || (rawCode >= 200 && rawCode <= 299) ? 200 : 400);
|
|
74
75
|
const body = isRaw || typeof data === 'string'
|
|
75
76
|
? data
|
|
76
77
|
: JSON.stringify(data?.getResponse ? data.getResponse : data);
|
|
77
78
|
return new Response(body, {
|
|
78
|
-
status,
|
|
79
|
+
status: httpStatus,
|
|
79
80
|
headers: { 'content-type': contentType }
|
|
80
81
|
});
|
|
81
82
|
},
|
|
@@ -124,7 +125,7 @@ export default class Controller extends BaseController {
|
|
|
124
125
|
if (checks) {
|
|
125
126
|
const checkResult = await checks(p);
|
|
126
127
|
if (checkResult !== true) {
|
|
127
|
-
const
|
|
128
|
+
const bizCode = checkResult?.code ?? 400;
|
|
128
129
|
const msg = checkResult?.message || (typeof checkResult === 'string' ? checkResult : 'error_validation');
|
|
129
130
|
let errorPayload = undefined;
|
|
130
131
|
if (checkResult?.payload) {
|
|
@@ -133,10 +134,10 @@ export default class Controller extends BaseController {
|
|
|
133
134
|
extraData: checkResult.payload.extraData ?? {}
|
|
134
135
|
};
|
|
135
136
|
}
|
|
136
|
-
return currentRes.status(
|
|
137
|
+
return currentRes.status(bizCode).send(new ResponseSchema({
|
|
137
138
|
status: false,
|
|
138
139
|
message: this.parseMessage(msg, currentReq.t, true),
|
|
139
|
-
code,
|
|
140
|
+
code: bizCode,
|
|
140
141
|
payload: errorPayload
|
|
141
142
|
}).getResponse);
|
|
142
143
|
}
|
|
@@ -149,11 +150,11 @@ export default class Controller extends BaseController {
|
|
|
149
150
|
logicResult = await logicResult.response();
|
|
150
151
|
}
|
|
151
152
|
if (logicResult?.status === false) {
|
|
152
|
-
const
|
|
153
|
-
return currentRes.status(
|
|
153
|
+
const bizCode = logicResult.code ?? 400;
|
|
154
|
+
return currentRes.status(bizCode).send(new ResponseSchema({
|
|
154
155
|
status: false,
|
|
155
156
|
message: this.parseMessage(logicResult.message || 'error_process', currentReq.t, true),
|
|
156
|
-
code
|
|
157
|
+
code: bizCode
|
|
157
158
|
}).getResponse);
|
|
158
159
|
}
|
|
159
160
|
const resResult = response ? await response({ ...p, logicResult }) : logicResult;
|
|
@@ -163,7 +164,7 @@ export default class Controller extends BaseController {
|
|
|
163
164
|
let finalData = undefined;
|
|
164
165
|
let finalExtraData = undefined;
|
|
165
166
|
let messageSource = 'success_process';
|
|
166
|
-
let
|
|
167
|
+
let bizSuccessCode = this.currentStore?.metadata?._code || 200;
|
|
167
168
|
const extract = (obj) => {
|
|
168
169
|
if (!obj || typeof obj !== 'object')
|
|
169
170
|
return;
|
|
@@ -183,7 +184,7 @@ export default class Controller extends BaseController {
|
|
|
183
184
|
if (obj.message)
|
|
184
185
|
messageSource = obj.message;
|
|
185
186
|
if (obj.code !== undefined)
|
|
186
|
-
|
|
187
|
+
bizSuccessCode = obj.code;
|
|
187
188
|
};
|
|
188
189
|
if (typeof resResult === 'string') {
|
|
189
190
|
messageSource = resResult;
|
|
@@ -199,11 +200,11 @@ export default class Controller extends BaseController {
|
|
|
199
200
|
extraData: finalExtraData ?? {}
|
|
200
201
|
};
|
|
201
202
|
}
|
|
202
|
-
return currentRes.status(
|
|
203
|
+
return currentRes.status(bizSuccessCode).send(new ResponseSchema({
|
|
203
204
|
status: true,
|
|
204
205
|
message: this.parseMessage(messageSource, currentReq.t, false),
|
|
205
206
|
payload,
|
|
206
|
-
code:
|
|
207
|
+
code: bizSuccessCode
|
|
207
208
|
}).getResponse);
|
|
208
209
|
}
|
|
209
210
|
catch (error) {
|