@reportportal/client-javascript 5.1.0 → 5.1.1

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/README.md CHANGED
@@ -61,7 +61,7 @@ When creating a client instance, you need to specify the following options:
61
61
  | headers | Optional | {} | The object with custom headers for internal http client. |
62
62
  | debug | Optional | false | This flag allows seeing the logs of the client. Useful for debugging. |
63
63
  | isLaunchMergeRequired | Optional | false | Allows client to merge launches into one at the end of the run via saving their UUIDs to the temp files at filesystem . At the end of the run launches can be merged using `mergeLaunches` method. Temp file format: `rplaunch-${launch_uuid}.tmp`. |
64
- | restClientConfig | Optional | Not set | The object with `agent` property for configure [http(s)](https://nodejs.org/api/https.html#https_https_request_url_options_callback) client, may contain other client options eg. `timeout`. |
64
+ | restClientConfig | Optional | Not set | The object with `agent` property for configure [http(s)](https://nodejs.org/api/https.html#https_https_request_url_options_callback) client, may contain other client options eg. `timeout`. For debugging and displaying logs you can set `debug: true` |
65
65
  | launchUuidPrint | Optional | false | Whether to print the current launch UUID. |
66
66
  | launchUuidPrintOutput | Optional | 'STDOUT' | Launch UUID printing output. Possible values: 'STDOUT', 'STDERR'. Works only if `launchUuidPrint` set to `true`. |
67
67
  | token | Deprecated | Not set | Use `apiKey` instead. |
package/VERSION CHANGED
@@ -1 +1 @@
1
- 5.1.1-SNAPSHOT
1
+ 5.1.2-SNAPSHOT
package/lib/rest.js CHANGED
@@ -16,6 +16,8 @@ class RestClient {
16
16
  this.baseURL = options.baseURL;
17
17
  this.headers = options.headers;
18
18
  this.restClientConfig = options.restClientConfig;
19
+
20
+ addLogger(this.restClientConfig ? this.restClientConfig.debug : false);
19
21
  }
20
22
 
21
23
  buildPath(path) {
@@ -112,4 +114,45 @@ method: ${method}`,
112
114
  }
113
115
  }
114
116
 
117
+ const addLogger = (debug) => {
118
+ if (debug) {
119
+ axios.interceptors.request.use((config) => {
120
+ const startDate = new Date();
121
+ config.startTime = startDate.valueOf();
122
+
123
+ console.log(`Request method=${config.method} url=${config.url} [${startDate.toISOString()}]`);
124
+
125
+ return config;
126
+ });
127
+
128
+ axios.interceptors.response.use(
129
+ (response) => {
130
+ const date = new Date();
131
+ const { status, config } = response;
132
+
133
+ console.log(
134
+ `Response status=${status} url=${config.url} time=${
135
+ date.valueOf() - config.startTime
136
+ }ms [${date.toISOString()}]`,
137
+ );
138
+
139
+ return response;
140
+ },
141
+ (error) => {
142
+ const date = new Date();
143
+ const { response, config } = error;
144
+ const status = response ? response.status : null;
145
+
146
+ console.log(
147
+ `Response ${status ? 'status=' + status : "message='" + error.message + "'"} url=${
148
+ config.url
149
+ } time=${date.valueOf() - config.startTime}ms [${date.toISOString()}]`,
150
+ );
151
+
152
+ return Promise.reject(error);
153
+ },
154
+ );
155
+ }
156
+ };
157
+
115
158
  module.exports = RestClient;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reportportal/client-javascript",
3
- "version": "5.1.0",
3
+ "version": "5.1.1",
4
4
  "description": "ReportPortal client for Node.js",
5
5
  "author": "ReportPortal.io",
6
6
  "scripts": {