Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stringify response body in case it is an object #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

forestjohnsonilm
Copy link

console.log({ errors: [{ exception: "GreedyLittleHandsException", message: "No pie for you!!" }] })

Will output:

{ errors: [Object] }

Which is not what I want.

Screenshot of pain point in log when debugging request

@forestjohnsonilm
Copy link
Author

I used JSON.stringify instead of util.inspect or console.debug because it's probably the most ubiquitous and it gets the job done.

I realize that the user can just read the docs and implement their own logging handler, but I think that the default behavior should work instead of not work. My colleague was convinced that this poor logging was the result of the HTTP server returning simplified responses for security reasons.

@alecl
Copy link

alecl commented Dec 26, 2016

Stringify always might be too bold and risky.

Thoughts on this instead which checks for a JSON content-type in the return? Alternatively, can check if the body is valid JSON regardless of headers.

          var responseLog = {
            debugId: this._debugId,
            headers: clone(res.headers),
            statusCode: res.statusCode
          }

          if (res && res.headers && res.headers["content-type"] && res.headers["content-type"].search(/json/i))
            responseLog.body = JSON.stringify(res.body);
          else
            responseLog.body = res.body;

          if (this.callback) {
            log('response', responseLog, this)
          }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants