When stream throws error, the event listener sends error object. The error.response.body should be decompressed when got.stream() is passed decompress: true option but actually, the response is gzip compressed if the server sends HTTPError with gzip encoding.
Second issue is that error.response.body is a buffer but ideally it should be stream.
...
Expected behavior
Response should be decompressed inside error object
The response should also be stream rather than buffer.
...
Code to reproduce
const got = require('got');
let stream = got("https://www.gumlet.com/non-exisent-path", {
isStream: true,
method: "GET",
decompress: true,
headers: {}
});
stream.on("response", (response) => {
console.log(response.headers);
console.log(response.statusCode)
});
stream.on("error", (err) => {
console.log("This is compressed:", err.response.body); // this should be decompressed.
console.log(Buffer.isBuffer(err.response.body)); // response.body is a buffer but ideally that should also be stream.
});
Checklist
[x] I have read the documentation.
[x] I have tried my code with the latest version of Node.js and Got.
Describe the bug
Actual behavior
When stream throws error, the event listener sends
error
object. Theerror.response.body
should be decompressed whengot.stream()
is passeddecompress: true
option but actually, the response isgzip
compressed if the server sends HTTPError with gzip encoding.Second issue is that
error.response.body
is a buffer but ideally it should be stream. ...Expected behavior
Code to reproduce
Checklist