@lark-apaas/client-toolkit 0.1.0-alpha.log.1 → 0.1.0-alpha.log.2

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.
@@ -1,5 +1,18 @@
1
1
  import axios from "axios";
2
2
  import { logger } from "../apis/logger.js";
3
+ function getRequestLogInfo(config) {
4
+ return {
5
+ url: config.url,
6
+ method: config.method?.toUpperCase(),
7
+ params: config.params,
8
+ data: config.data,
9
+ headers: {
10
+ ...config.headers,
11
+ 'X-Suda-Csrf-Token': config.headers['X-Suda-Csrf-Token'] ? '[REDACTED]' : void 0,
12
+ Authorization: config.headers.Authorization ? '[REDACTED]' : void 0
13
+ }
14
+ };
15
+ }
3
16
  function initAxiosConfig(axiosInstance) {
4
17
  if (!axiosInstance) axiosInstance = axios;
5
18
  axiosInstance.defaults.timeout = 10000;
@@ -9,30 +22,14 @@ function initAxiosConfig(axiosInstance) {
9
22
  if (csrfToken) config.headers['X-Suda-Csrf-Token'] = csrfToken;
10
23
  logger.info({
11
24
  type: 'HTTP Request',
12
- url: config.url,
13
- method: config.method?.toUpperCase(),
14
- params: config.params,
15
- data: config.data,
16
- headers: {
17
- ...config.headers,
18
- 'X-Suda-Csrf-Token': config.headers['X-Suda-Csrf-Token'] ? '[REDACTED]' : void 0,
19
- Authorization: config.headers.Authorization ? '[REDACTED]' : void 0
20
- }
25
+ ...getRequestLogInfo(config)
21
26
  });
22
27
  return config;
23
28
  }, (error)=>{
24
29
  logger.error({
25
30
  type: 'HTTP Request',
31
+ ...getRequestLogInfo(error.config),
26
32
  message: error.message,
27
- url: error.config?.url,
28
- method: error.config?.method?.toUpperCase(),
29
- params: error.config?.params,
30
- data: error.config?.data,
31
- headers: {
32
- ...error.config?.headers,
33
- 'X-Suda-Csrf-Token': error.config?.headers['X-Suda-Csrf-Token'] ? '[REDACTED]' : void 0,
34
- Authorization: error.config?.headers.Authorization ? '[REDACTED]' : void 0
35
- },
36
33
  stack: error.stack
37
34
  });
38
35
  return Promise.reject(error);
@@ -40,18 +37,17 @@ function initAxiosConfig(axiosInstance) {
40
37
  axiosInstance.interceptors.response.use((response)=>{
41
38
  logger.info({
42
39
  type: 'HTTP Response',
43
- url: response.config.url,
44
- method: response.config.method?.toUpperCase(),
40
+ ...getRequestLogInfo(response.config),
45
41
  status: response.status,
46
42
  statusText: response.statusText,
43
+ responseData: response.data,
47
44
  responseTime: Date.now() - response.config._startTime
48
45
  });
49
46
  return response;
50
47
  }, (error)=>{
51
48
  logger.error({
52
49
  type: 'HTTP Response',
53
- url: error.config?.url,
54
- method: error.config?.method?.toUpperCase(),
50
+ ...getRequestLogInfo(error.config),
55
51
  status: error.response?.status,
56
52
  statusText: error.response?.statusText,
57
53
  message: error.message,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/client-toolkit",
3
- "version": "0.1.0-alpha.log.1",
3
+ "version": "0.1.0-alpha.log.2",
4
4
  "types": "./lib/index.d.ts",
5
5
  "main": "./lib/index.js",
6
6
  "files": [