We have that piece of code on multiple locations:
if (this.debug) {
cmd.log('Executing web request...');
cmd.log(requestOptions);
cmd.log('');
}
But whenever requestOptions has headers specified like:
const requestOptions: any = {
...
headers: Utils.getRequestHeaders({
authorization: `Bearer ${accessToken}`,
accept: 'application/json;odata=nometadata'
})
};
then the output for the headers section when we specify --debug is
Executing web request...
url : https://xxx.sharepoint.com/sites/xxx/_api/contextinfo
headers: [object Object]
json : true
This can be changed to
if (this.debug) {
cmd.log('Executing web request...');
cmd.log(JSON.stringify(requestOptions));
cmd.log('');
}
to print the correct output.
I did not wanted to change it before discussion because it has 24 occurrences in the solution.
Your suggestion makes perfect sense @VelinGeorgiev. It was printing ok initially, but when we changed logging, I missed this apparently.
When using JSON.stringify it would be helpful to pretty print it, so using JSON.stringify(requestOptions, null, 2) instead which will produce input with indenting.
Thinking about it: since the information about the request is displayed in a table, let's not JSON prettify the headers, as that would break the rendering, so let's stick to the initial JSON.stringify(requestOptions) you proposed.
Recently, when building one of the commands, I spotted an issue with easy-table and transposed printing. To fix the bug, I build alternative version of transposed in the CLI. We could fix the issue you mentioned centrally, in the code I added rather than changing all occurrences.