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

Regarding "switch on response's status" #60

Closed
tobireif opened this issue Jun 3, 2015 · 2 comments
Closed

Regarding "switch on response's status" #60

tobireif opened this issue Jun 3, 2015 · 2 comments

Comments

@tobireif
Copy link

tobireif commented Jun 3, 2015

Regarding https://fetch.spec.whatwg.org/#http-fetch -> "switch on response's status":

Dear WHATWG

Shouldn't a 404 be handled as error?

While using a fetch() polyfill I was surprised that my .catch block wasn't called.

Now I added this:

if (response.status === 200) {
  return response;
} else {
  throw new Error(response.statusText);
}

But I had expected fetch() to throw an error when it receives (eg) a 404.
I wanted to (API nomenclature) "fetch" a file and the server replied (HTTP status) "not found" - this is a failure regarding the objective of fetching the file, and it might surprise other users of your API as well that it doesn't get reported as error.

Perhaps specify it as default behavior? (throwing an error on 404 etc)
And perhaps in addition offer some flag which gives the API user the option of handling the status code himself, completely.

Tobi

@domenic
Copy link
Member

domenic commented Jun 3, 2015

Dupe of #18. You may be interested in response.ok. The discussion in #18 is quite good though and hopefully will address why the proposal isn't really feasible.

@domenic domenic closed this as completed Jun 3, 2015
@tobireif
Copy link
Author

tobireif commented Jun 3, 2015

(Sorry for the dupe, will post at #18 .)

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

No branches or pull requests

2 participants