Skip to content

Commit

Permalink
Fix throwing errors when using got.stream() (#550)
Browse files Browse the repository at this point in the history
  • Loading branch information
szmarczak authored and sindresorhus committed Aug 9, 2018
1 parent ecf3180 commit ae5b114
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion source/create.js
Expand Up @@ -20,7 +20,11 @@ const create = defaults => {
options = mergeOptions(defaults.options, options);
return defaults.handler(normalizeArguments(url, options, defaults), next);
} catch (error) {
return Promise.reject(error);
if (options.stream) {
throw error;
} else {
return Promise.reject(error);
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions test/error.js
Expand Up @@ -133,3 +133,9 @@ test.serial('catch error in mimicResponse', async t => {

await t.throws(proxiedGot(s.url), {message: 'Error in mimic-response'});
});

test('errors are thrown directly when options.stream is true', t => {
t.throws(() => got(s.url, {stream: true, body: {}}), {
message: 'The `body` option must be a stream.Readable, string or Buffer'
});
});

0 comments on commit ae5b114

Please sign in to comment.