question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

how to log entire response (at least statusCode & body)

See original GitHub issue

I’m trying to correlate the response statusCode with the response body.

How can I get a log of the body & the statusCode? I attempted this:

...blah
scenarios:
  - name: POST /foo
    flow:
...blah
      - post:
          url: "/foo"
          capture:
            - json: "$"
              as: fooBody
...blah
      - log: "{{statusCode}} => {{ fooBody }}"

Obviously statusCode logs as undefined. The fooBody works.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:2
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

12reactions
JGro144commented, May 5, 2020

If you add processor: "./my-functions.js" into your test.yml files config then add afterResponse: "printStatus" to your call in the flow like

- get:
      url: "/login"
      afterResponse: "printStatus"

then in the my-functions.js file add a

function printStatus (requestParams, response, context, ee, next) {
    console.log(`${response.statusCode.uri.path}: ${response.statusCode}`);  
    return next();
}

make sure in the file you include

module.exports = {
    printStatus: printStatus
}
8reactions
tbradley-sanscommented, Sep 20, 2019

Yeah, I discovered earlier this week that DEBUG=http:response doesn’t actually print out the HTTP response status code. That’s the single most important part of any response, in my opinion.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring Boot - How to log all requests and responses with ...
If you want the headers to be included in the log, then you should add: "spring.http.log-request-details=true" to you application.properties file. – jfajunior.
Read more >
How to Get Response Body When Testing the Status Code in ...
In this tutorial, we'll look at how to access the status code and response body returned from a REST request using WebFlux's WebClient....
Read more >
Response.status - Web APIs - MDN Web Docs
The status read-only property of the Response interface contains the HTTP status codes of the response.
Read more >
How to Read Json Response Body using Rest Assured?
restassured.response.ResponseBody. This class represents the Body of a received Response. Using this class you can get and validate complete or ...
Read more >
REST Assured Tutorial 69 – Response Logging In Rest Assured
all () – Logs everything in the response, including e.g. headers, cookies, body. Pretty-prints the body if content-type is either either XML, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found