@riocrypto/common-server 1.0.1683 → 1.0.1684
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.
|
@@ -8,28 +8,33 @@ const logger_1 = __importDefault(require("../services/logger"));
|
|
|
8
8
|
const axiosWithLogging = axios_1.default.create();
|
|
9
9
|
// Request Interceptor
|
|
10
10
|
axiosWithLogging.interceptors.request.use((config) => {
|
|
11
|
+
var _a;
|
|
11
12
|
// Combine and log the full request configuration
|
|
12
13
|
const logMessage = `Request: method=${config.method}, url=${config.url}, headers=${JSON.stringify(config.headers)}, data=${JSON.stringify(config.data)}`;
|
|
13
|
-
logger_1.default.getLogger().info(logMessage);
|
|
14
|
+
((_a = logger_1.default.getLogger()) === null || _a === void 0 ? void 0 : _a.info(logMessage)) || console.log(logMessage);
|
|
14
15
|
return config;
|
|
15
16
|
}, (error) => {
|
|
17
|
+
var _a;
|
|
16
18
|
// Log the request error with combined details
|
|
17
|
-
logger_1.default.getLogger().info(`Request Error: ${error}`)
|
|
19
|
+
((_a = logger_1.default.getLogger()) === null || _a === void 0 ? void 0 : _a.info(`Request Error: ${error}`)) ||
|
|
20
|
+
console.log(`Request Error: ${error}`);
|
|
18
21
|
return Promise.reject(error);
|
|
19
22
|
});
|
|
20
23
|
// Response Interceptor
|
|
21
24
|
axiosWithLogging.interceptors.response.use((response) => {
|
|
25
|
+
var _a;
|
|
22
26
|
// Combine and log the full response details
|
|
23
27
|
const logMessage = `Response: url=${response.config.url}, status=${response.status}, data=${JSON.stringify(response.data)}`;
|
|
24
|
-
logger_1.default.getLogger().info(logMessage);
|
|
28
|
+
((_a = logger_1.default.getLogger()) === null || _a === void 0 ? void 0 : _a.info(logMessage)) || console.log(logMessage);
|
|
25
29
|
return response;
|
|
26
30
|
}, (error) => {
|
|
31
|
+
var _a;
|
|
27
32
|
// Combine and log the response error details
|
|
28
33
|
let logMessage = `Response Error: url=${error.config ? error.config.url : "unknown"}, message=${error.message}`;
|
|
29
34
|
if (error.response) {
|
|
30
35
|
logMessage += `, status=${error.response.status}, data=${JSON.stringify(error.response.data)}`;
|
|
31
36
|
}
|
|
32
|
-
logger_1.default.getLogger().info(logMessage);
|
|
37
|
+
((_a = logger_1.default.getLogger()) === null || _a === void 0 ? void 0 : _a.info(logMessage)) || console.log(logMessage);
|
|
33
38
|
return Promise.reject(error);
|
|
34
39
|
});
|
|
35
40
|
exports.default = axiosWithLogging;
|