Skip to content
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

Fix throwing errors when using got.stream() #550

Merged
merged 1 commit into from
Aug 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion source/create.js
Original file line number Diff line number Diff line change
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;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could return throwing EventEmitter here. What do you think?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's a user-error and should fail immediately.

} else {
return Promise.reject(error);
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions test/error.js
Original file line number Diff line number Diff line change
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'
});
});