-
-
Notifications
You must be signed in to change notification settings - Fork 935
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
Stream does not report errors when status code is different of 2xx #1269
Comments
It does error. It's just that you do not handle it. Try adding a |
Thank you for your quick response. Indeed, it is working if we add a PassThrough step to the pipeline. I think, this should be added to your documentation (we almost lost critical data because of this...) const stream = require('stream');
const {promisify} = require('util');
const fs = require('fs');
const got = require('got');
const pipeline = promisify(stream.pipeline);
(async () => {
await pipeline(
got.stream('https://sindresorhus.com'),
fs.createWriteStream('index.html')
);
// For POST, PUT, and PATCH methods `got.stream` returns a `stream.Writable`
await pipeline(
fs.createReadStream('index.html'),
got.stream.post('https://sindresorhus.com'),
new stream.PassThrough()
);
})(); |
Maybe... But the
|
I made a Node.js issue about it some while ago, and they stated that it's "correct behavior to fix broken streams". Unfortunately they're not aware that they broke more things than they fixed. |
OK, thank you to have taken your time to response. I think the behavior of pipeline is dangerous and I am sure that I am not the only person who did not expected to work like this. Maybe a little note on your REAME.md to warn that the requests errors are not catched (and to add a PassThrough() step to be sure it does) would be great. |
Describe the bug
When got.stream is used and the server return an error code, got does not report the error. This makes very difficult to know if the request was a success (and more importantly, it lets you think that your request was a success.) This is not consistent with other methods.
Expected behavior
got.stream should trigger an "error" event when a server responses with a 4xx or 5xx status code
Code to reproduce
The text was updated successfully, but these errors were encountered: