Skip to content

Conversation

@idoo
Copy link

@idoo idoo commented Aug 30, 2016

No description provided.

.then(function(response) {
if (response.status >= 400) {
if (response.status >= 200 || response.status < 400) {
return response.json();
Copy link

Choose a reason for hiding this comment

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

Not all requests with code >=200 and <400 will have valid JSON body.

Copy link
Author

Choose a reason for hiding this comment

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

as well >=400 did not pass this requirement

Copy link

Choose a reason for hiding this comment

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

if (response.status >= 400) {
if (response.status >= 200 || response.status < 400) {
return response.json();

Copy link

Choose a reason for hiding this comment

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

Is this empty line is unnecessary?

@matthew-andrews
Copy link
Owner

I mean I guess it is true that the status codes between 200 and 400 would be ‘good’ … but if you are in control of your backend you would know what valid statuses it would reply with and in this case it would only ever reply with 200 if it's healthy… (In some ways it's safer to treat unexpected statuses as errors on the front end, even if they're technically valid HTTP status codes because you may want to have different behaviour)

In any case if you wanted to have such a broad check for “ok” statuses I think if (response.ok) { would be a better check …

I think I will close this without change but if you disagree please let me know.

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.

4 participants