Browse Source

Correctly forward stream errors (#424)

Related to #388
fix-progress-browserify
Sindre Sorhus 7 years ago
committed by GitHub
parent
commit
974473aadb
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      index.js
  2. 7
      test/gzip.js

4
index.js

@ -416,6 +416,10 @@ function asStream(opts) {
const statusCode = res.statusCode;
res.on('error', err => {
proxy.emit('error', new got.ReadError(err, opts));
});
res.pipe(output);
if (statusCode !== 304 && (statusCode < 200 || statusCode > 299)) {

7
test/gzip.js

@ -66,6 +66,13 @@ test('handles gzip error', async t => {
t.is(err.name, 'ReadError');
});
test('handles gzip error - stream', async t => {
const err = await t.throws(getStream(got.stream(`${s.url}/corrupted`)));
t.is(err.message, 'incorrect header check');
t.is(err.path, '/corrupted');
t.is(err.name, 'ReadError');
});
test('decompress option opts out of decompressing', async t => {
const response = await got(s.url, {decompress: false});
t.true(Buffer.compare(response.body, gzipData) === 0);

Loading…
Cancel
Save