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

Reject normalization errors with CancelableRequest #1035

Merged
merged 3 commits into from
Jan 23, 2020
Merged

Reject normalization errors with CancelableRequest #1035

merged 3 commits into from
Jan 23, 2020

Conversation

callmehiphop
Copy link
Contributor

Closes #1025

In the event of an error being thrown during argument normalization a normal promise was being returned which prevented users from calling any of the CancelableRequest convenience methods. This changes makes it so a rejected CancelableRequest is returned instead.

Checklist

  • I have read the documentation.
  • I have included a pull request description of my changes.
  • I have included some tests.

Sorry, something went wrong.

test/error.ts Outdated
@@ -193,6 +193,12 @@ test('errors are thrown directly when options.stream is true', t => {
});
});

test('normalization errors using convenience methods', async t => {
const error = await t.throwsAsync(got('undefined/https://example.com'));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
const error = await t.throwsAsync(got('undefined/https://example.com'));
await t.throwsAsync(got('undefined/https://example.com').json().text().buffer(), 'Invalid URL');

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed!

Copy link
Collaborator

Choose a reason for hiding this comment

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

You forgot to test .text() and .buffer(). Make sure that the error message is Invalid URL. As in the suggestion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I must have missed the Invalid URL part. Do you want a separate assertion for each method?

Copy link
Collaborator

Choose a reason for hiding this comment

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

No need to

@szmarczak szmarczak merged commit fddecab into sindresorhus:master Jan 23, 2020
@szmarczak
Copy link
Collaborator

Looks good, thanks! 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect url causes .json is not a function error
2 participants