FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Stringify response body in case it is an object by forestjohnsonilm · Pull Request #7 · request/request-debug · GitHub

Stringify response body in case it is an object - #7

Open
forestjohnsonilm wants to merge 1 commit into
request:masterfrom
forestjohnsonilm:master
Open

Stringify response body in case it is an object#7
forestjohnsonilm wants to merge 1 commit into
request:masterfrom
forestjohnsonilm:master

Conversation

Copy link
Copy Markdown

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

Will output:

{ errors: [Object] }

Which is not what I want.

Copy link
Copy Markdown
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 commented Dec 26, 2016

Copy link
Copy Markdown

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)
          }

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL