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.

Piping the response to a end file: get response status

See original GitHub issue

How can I get response status if response is piped to file stream?

See code:

var client = supertest(...);
...
// Create writable stream
var writeStream = temp.createWriteStream();
temp.track();

// Superagent request
var req = client.get('/...');

req.on('end', function() {
    // Here we can read file content
    // It can contain actual file content
    // Or JSON string representing error
    // For example {'code': 'F-0001' , 'message': 'File not found'}
    // We should parse this if response code != 200
    // How can we get it here?
    ...
});

// Piping the response to a file
req.pipe(writeStream);

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
tjconceptcommented, Oct 16, 2014

Try this:

req.on('response', function( res ) {
  console.log(res.status);
});
0reactions
juancoencommented, Jun 26, 2015

I’ve tried this and the ‘response’ callback do not work with get requests.

I’m not sure if this is the ‘proper way’ to do this, but if you really need it, you can access the response status code in the ‘end’ callback doing

this.res.statusCode;

This breaks encapsulation, so be aware that it might change in future superagent versions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Piping the response to a end file: get response status #469
How can I get response status if response is piped to file stream? See code: var client = supertest(...); ... // Create writable...
Read more >
nodejs request module check for response status before pipe ...
I am currently using "request" module to download some files. The code looks like function download(url, fileName, path) { return ...
Read more >
Developers - Piping the response to a end file: get response status -
Coming soon: A brand new website interface for an even better experience!
Read more >
Streams, Piping, and Their Error Handling in Node.js - Medium
For an HTTP request, we created a read stream for a file and we piped it to the HTTP response write stream. In...
Read more >
Invoke an AWS Lambda function in a pipeline in CodePipeline
On the status page for your pipeline, in the CodeDeploy action, choose Details. ... indexOf(search) > -1; } }; http.get(url, function(response) ...
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