Getting the response status when piping data
See original GitHub issueHi,
I need to download data with Node and I’m using superagent to pipe data to a file stream. The example on the documentation works fine for simple cases, but I’m now trying to handle status like 403 or 404.
I understand these are not actual errors so the response body will be piped. I should, however, receive an event that tells me the status so I can abort
before I write the data. Unfortunately, the end
callbacks are called without the response/error when the request is piped. The callback arguments are always undefined
.
Here’s the list of handlers I’ve tried:
superagent
.get('http://httpbin.org/image/png')
.on('response', (response) =>
{
console.log('response', response);
})
.on('error', (error) =>
{
console.log('error', error);
})
.on('end', (error, response) =>
{
console.log('end', error, response);
})
.end(response =>
{
console.log('end', response);
})
.pipe(file);
What’s the proper way to get the response status in that case?
Thanks, Warren.
Issue Analytics
- State:
- Created 9 years ago
- Reactions:6
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Getting the response status when piping data #565 - GitHub
Hi,. I need to download data with Node and I'm using superagent to pipe data to a file stream. The example on the...
Read more >How does simply piping to the response object render data to ...
The answer is that pipe returns the destination stream. That means when you do a.pipe(b) , you'll get b back from the method...
Read more >Get exit status of process that's piped to another
bash and zsh have an array variable that holds the exit status of each element (command) of the last pipeline executed by the...
Read more >Pipelines API - GitLab Docs
Pipelines pagination. By default, GET requests return 20 results at a time because the API results are paginated. Read more on pagination.
Read more >Invoke an AWS Lambda function in a pipeline in CodePipeline
CodePipeline(); // Retrieve the Job ID from the Lambda action var jobId ... statusCode; response.on('data', function (chunk) { pageObject.body += chunk; }); ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Is this still the suggested way to handle errors when downloading/streaming to file? I get
request.abort is not a function
running this.You get the abort event, and no more. It stops downloading further data.