sasai-common-utils 1.0.20 → 1.0.22
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/.env
ADDED
package/package.json
CHANGED
|
@@ -10,7 +10,6 @@ const logRequest = (request, logger) => {
|
|
|
10
10
|
const { method, url, headers, data, params, query } = request;
|
|
11
11
|
const api = "REQUEST"
|
|
12
12
|
const logObject = { method, url, headers, requestBody: data, parameters: query, api };
|
|
13
|
-
|
|
14
13
|
logger.logInfo("Axios Request", logObject);
|
|
15
14
|
return request;
|
|
16
15
|
};
|
|
@@ -54,14 +53,30 @@ const logError = (error, logger) => {
|
|
|
54
53
|
* @param {Object} axiosInstance - Axios instance.
|
|
55
54
|
* @param {Object} logger - Logger instance.
|
|
56
55
|
*/
|
|
57
|
-
const attachAxiosLogger = (axiosInstance, logger) => {
|
|
56
|
+
const attachAxiosLogger = (axiosInstance, logger, apm) => {
|
|
58
57
|
axiosInstance.interceptors.request.use(
|
|
59
|
-
(request) =>
|
|
58
|
+
(request) =>{
|
|
59
|
+
request.headers = {
|
|
60
|
+
...request.headers,
|
|
61
|
+
"x-b3-traceid": apm?.currentTraceIds?.["trace.id"] ?? "",
|
|
62
|
+
"x-b3-spanid": apm?.currentTraceIds?.["transaction.id"] ?? "",
|
|
63
|
+
"x-b3-parentspanid": apm?.currentTraceIds?.["transaction.id"] ?? ""
|
|
64
|
+
};
|
|
65
|
+
return logRequest(request, logger)
|
|
66
|
+
} ,
|
|
60
67
|
(error) => logError(error, logger)
|
|
61
68
|
);
|
|
62
69
|
|
|
63
70
|
axiosInstance.interceptors.response.use(
|
|
64
|
-
(response) =>
|
|
71
|
+
(response) => {
|
|
72
|
+
response.headers = {
|
|
73
|
+
...response.headers,
|
|
74
|
+
"x-b3-traceid": apm?.currentTraceIds?.["trace.id"] ?? "",
|
|
75
|
+
"x-b3-spanid": apm?.currentTraceIds?.["transaction.id"] ?? "",
|
|
76
|
+
"x-b3-parentspanid": apm?.currentTraceIds?.["transaction.id"] ?? ""
|
|
77
|
+
};
|
|
78
|
+
return logResponse(response, logger);
|
|
79
|
+
} ,
|
|
65
80
|
(error) => logError(error, logger)
|
|
66
81
|
);
|
|
67
82
|
};
|
|
@@ -140,7 +140,7 @@ if (config.DEBUG_MODE === DEBUG_MODES.FILE) {
|
|
|
140
140
|
step: data?.step,
|
|
141
141
|
error: data?.error?.message,
|
|
142
142
|
stack: data?.error?.stack,
|
|
143
|
-
|
|
143
|
+
responseStatus: errorResponse?.status || HTTP_STATUS_CODES.BAD_REQUEST,
|
|
144
144
|
path: errorResponse?.config?.url || req?.originalUrl,
|
|
145
145
|
headers: errorResponse?.config?.headers || {},
|
|
146
146
|
requestBody: errorResponse?.config?.body || req?.body,
|
|
@@ -149,7 +149,7 @@ if (config.DEBUG_MODE === DEBUG_MODES.FILE) {
|
|
|
149
149
|
};
|
|
150
150
|
data.thread = "";
|
|
151
151
|
data.class = "";
|
|
152
|
-
const tokenData = jwt.decode(
|
|
152
|
+
const tokenData = jwt.decode(req?.headers?.authorization?.split(" ")[1], { complete: true })?.payload;
|
|
153
153
|
data.message.tokenDetails = {
|
|
154
154
|
"customerId":tokenData?.customerId ?? "",
|
|
155
155
|
"mid":tokenData?.mid ?? "",
|
|
@@ -158,6 +158,7 @@ if (config.DEBUG_MODE === DEBUG_MODES.FILE) {
|
|
|
158
158
|
if (data?.step) delete data?.step;
|
|
159
159
|
if (data?.error) delete data.error;
|
|
160
160
|
data["level"] = LOG_LEVELS.ERROR;
|
|
161
|
+
data.message = JSON.stringify(data.message);
|
|
161
162
|
logger.error(data);
|
|
162
163
|
};
|
|
163
164
|
|