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

Don't throw HTTPError on 304 responses #252

Merged
merged 4 commits into from
May 1, 2017

Conversation

lukechilds
Copy link
Sponsor Contributor

Resolves #251

@lukechilds
Copy link
Sponsor Contributor Author

@sindresorhus Continuing discussion from here: #251 (comment)

I've added a test 👍

When writing it I noticed that the mock 404 route is wrapped with setTimeout? Why is this? Tests still pass if I comment out setTimout. Should I be doing that for my 304 route?

Regarding the readme update, is it really necessary to mention a 304 response will have an empty body in the readme? That's normal HTTP behaviour, if people are sending if-modified-since headers then they are gonna be expecting to handle 304s.

@sindresorhus
Copy link
Owner

When writing it I noticed that the mock 404 route is wrapped with setTimeout? Why is this? Tests still pass if I comment out setTimout. Should I be doing that for my 304 route?

Nah, you don't need. According to git blame, it was added to workaround some flakyness. Probably related to older Node.js versions. 46d0d4a

@floatdrop Let's just remove that setTimeout now? I don't think it applies anymore.

Regarding the readme update, is it really necessary to mention a 304 response will have an empty body in the readme? That's normal HTTP behaviour, if people are sending if-modified-since headers then they are gonna be expecting to handle 304s.

Expecting users to know something is like asking for support questions. Doesn't hurt to have a quick reminder about it.

test/http.js Outdated
t.is(response.body, '');
} catch (err) {
t.fail('Exception was thrown');
}
Copy link
Owner

Choose a reason for hiding this comment

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

Use t.notThrows rather than try/catch:

const p = got(`${s.url}/304`)
await t.notThrows(p);
const response = await p;
t.is(response.statusCode, 304);
t.is(response.body, '');

test/http.js Outdated
@@ -56,6 +61,16 @@ test('error with code', async t => {
}
});

test('304 doesn\'t throw', async t => {
Copy link
Owner

Choose a reason for hiding this comment

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

status code 304 doesn't throw

@floatdrop
Copy link
Contributor

@sindresorhus yeah, it can be removed now. Tests were failing without it on 0.10/0.12 I think.

@lukechilds
Copy link
Sponsor Contributor Author

Ok, I've made those changes.

@sindresorhus is the wording/position in the readme ok?

@sindresorhus sindresorhus merged commit 7b12b75 into sindresorhus:master May 1, 2017
@sindresorhus
Copy link
Owner

Yup. Looks good. Thanks again :)

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.

None yet

3 participants