Cli-microsoft365: Output with `headers: [object Object]` when --debug specified on multiple locations

Created on 13 Dec 2017  路  3Comments  路  Source: pnp/cli-microsoft365

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.

enhancement work in progress

All 3 comments

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.

Was this page helpful?
0 / 5 - 0 ratings