@xrystal/core 3.16.7 → 3.16.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
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
-
import LoggerService from '../logger';
|
|
3
2
|
import { ProtocolEnum } from '../../utils/index';
|
|
4
3
|
export declare const controllerContextStorage: AsyncLocalStorage<{
|
|
5
4
|
protocol?: ProtocolEnum;
|
|
@@ -33,7 +32,8 @@ export interface CustomRequest {
|
|
|
33
32
|
body?: any;
|
|
34
33
|
params: Record<string, any>;
|
|
35
34
|
query: Record<string, any>;
|
|
36
|
-
|
|
35
|
+
lang: string;
|
|
36
|
+
t: (k: string, args?: any) => string;
|
|
37
37
|
}
|
|
38
38
|
export interface CustomResponse {
|
|
39
39
|
status: (code: number) => CustomResponse;
|
|
@@ -42,7 +42,7 @@ export interface CustomResponse {
|
|
|
42
42
|
locals: Record<string, any>;
|
|
43
43
|
}
|
|
44
44
|
declare abstract class Controller {
|
|
45
|
-
protected loggerService:
|
|
45
|
+
protected loggerService: any;
|
|
46
46
|
protected supportedProtocols: ProtocolEnum[];
|
|
47
47
|
constructor({ loggerService }: any);
|
|
48
48
|
protected get protocol(): ProtocolEnum;
|
|
@@ -19,7 +19,7 @@ class Controller {
|
|
|
19
19
|
const store = this.currentStore;
|
|
20
20
|
const identityT = (k) => k;
|
|
21
21
|
if (!store)
|
|
22
|
-
return { url: '', method: '', headers: {}, params: {}, query: {}, t: identityT };
|
|
22
|
+
return { url: '', method: '', headers: {}, params: {}, query: {}, lang: 'en', t: identityT };
|
|
23
23
|
const { ctx, req: nativeReq } = store;
|
|
24
24
|
const source = nativeReq || ctx?.request || ctx;
|
|
25
25
|
return {
|
|
@@ -32,6 +32,7 @@ class Controller {
|
|
|
32
32
|
params: ctx?.params || nativeReq?.params || source?.params || {},
|
|
33
33
|
query: ctx?.query || nativeReq?.query || source?.query || {},
|
|
34
34
|
accounts: ctx?.user || nativeReq?.accounts || source?.accounts,
|
|
35
|
+
lang: ctx?.lang || nativeReq?.lang || 'en',
|
|
35
36
|
t: ctx?.t || nativeReq?.t || identityT
|
|
36
37
|
};
|
|
37
38
|
}
|
|
@@ -117,7 +118,7 @@ export class ControllerService extends Controller {
|
|
|
117
118
|
const successObj = {
|
|
118
119
|
status: true,
|
|
119
120
|
message: Array.isArray(resResult.message)
|
|
120
|
-
? responseMessageHelper.successFully(resResult.message[0], resResult.message[1], req.
|
|
121
|
+
? responseMessageHelper.successFully(resResult.message[0], resResult.message[1], req.lang)
|
|
121
122
|
: resResult.message,
|
|
122
123
|
payload: logicResult?.payload !== undefined ? logicResult.payload : logicResult
|
|
123
124
|
};
|
|
@@ -126,10 +127,10 @@ export class ControllerService extends Controller {
|
|
|
126
127
|
return res.send(logicResult?.payload !== undefined ? logicResult.payload : logicResult);
|
|
127
128
|
}
|
|
128
129
|
catch (error) {
|
|
129
|
-
this.loggerService.
|
|
130
|
+
this.loggerService.error(`Controller Error: ${error.message}`, { stack: error.stack });
|
|
130
131
|
return this.res.status(500).send({
|
|
131
132
|
status: false,
|
|
132
|
-
message: error.message
|
|
133
|
+
message: error.message || "Internal Server Error"
|
|
133
134
|
});
|
|
134
135
|
}
|
|
135
136
|
}
|