You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
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.
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:
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
The text was updated successfully, but these errors were encountered: