Skip to content

Commit

Permalink
Merge pull request #189 from reportportal/develop
Browse files Browse the repository at this point in the history
Release 5.1.1
  • Loading branch information
AmsterGet authored Jan 23, 2024
2 parents 3203e02 + 90e751d commit 0a66d7c
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ jobs:
echo "patch" > ${{ env.versionFragmentFileName }}
git status
git add ${{ env.versionFileName }}
git add ${{ env.versionFragmentFileName }}
git commit -m "${{ needs.calculate-version.outputs.releaseVersion }} -> ${{ steps.bumpSnapshotVersion.outputs.next-version }}-SNAPSHOT"
git push origin develop
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
### Added
- Debug logs for RestClient.

## [5.1.0] - 2024-01-19
### Changed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ When creating a client instance, you need to specify the following options:
| headers | Optional | {} | The object with custom headers for internal http client. |
| debug | Optional | false | This flag allows seeing the logs of the client. Useful for debugging. |
| 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`. |
| 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`. |
| 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` |
| launchUuidPrint | Optional | false | Whether to print the current launch UUID. |
| launchUuidPrintOutput | Optional | 'STDOUT' | Launch UUID printing output. Possible values: 'STDOUT', 'STDERR'. Works only if `launchUuidPrint` set to `true`. |
| token | Deprecated | Not set | Use `apiKey` instead. |
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.1.0
5.1.1-SNAPSHOT
43 changes: 43 additions & 0 deletions lib/rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class RestClient {
this.baseURL = options.baseURL;
this.headers = options.headers;
this.restClientConfig = options.restClientConfig;

addLogger(this.restClientConfig ? this.restClientConfig.debug : false);
}

buildPath(path) {
Expand Down Expand Up @@ -112,4 +114,45 @@ method: ${method}`,
}
}

const addLogger = (debug) => {
if (debug) {
axios.interceptors.request.use((config) => {
const startDate = new Date();
config.startTime = startDate.valueOf();

console.log(`Request method=${config.method} url=${config.url} [${startDate.toISOString()}]`);

return config;
});

axios.interceptors.response.use(
(response) => {
const date = new Date();
const { status, config } = response;

console.log(
`Response status=${status} url=${config.url} time=${
date.valueOf() - config.startTime
}ms [${date.toISOString()}]`,
);

return response;
},
(error) => {
const date = new Date();
const { response, config } = error;
const status = response ? response.status : null;

console.log(
`Response ${status ? 'status=' + status : "message='" + error.message + "'"} url=${
config.url
} time=${date.valueOf() - config.startTime}ms [${date.toISOString()}]`,
);

return Promise.reject(error);
},
);
}
};

module.exports = RestClient;
2 changes: 1 addition & 1 deletion version_fragment
Original file line number Diff line number Diff line change
@@ -1 +1 @@
minor
patch

0 comments on commit 0a66d7c

Please sign in to comment.