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
Option to require response.ok #103
Comments
This discussion started at w3c/ServiceWorker#407 |
Would this be added to Cache add/addAll as well? |
I think… cache.addAll([
'/hello/',
'/world/'
].map(u => new Request(url, {requiredStatus: 'ok'}))); …would be enough |
I don't think this sugar is worth it. People just need to realize the underlying mental model is that fetch returns responses, and responses can be not-OK, and they should handle that. |
It's a little more than that: installEvent.waitUntil(
caches.open('static-v1').then(cache => {
return Promise.all([
'/hello/',
'/world/'
].map(url => {
let request = new Request(url);
return fetch(request).then(response => {
if (!response.ok) throw Error("NOT OK");
return cache.put(request, response);
});
}));
})
);
// vs…
installEvent.waitUntil(
caches.open('static-v1').then(cache => {
cache.addAll([
'/hello/',
'/world/'
].map(u => new Request(u, {requiredStatus: 'ok'})));
})
); Also, the former isn't atomic. This could just be an option in |
What about adding the option to CacheStorage.open() so the entire Cache object could be marked requiredStatus 'ok'? |
IMO, since |
Media elements, Feels like there's call for this to be part of fetch to standardise what's considered and error and what isn't. |
I know |
I guess |
Yeah, I guess the "ok" check would be just before returning the response to the caller in main fetch. |
Another data point from https://w3c.github.io/network-error-logging/#h-reporting:
The definition of what constitutes a network failure would remove the ambiguity here. But then, that spec doesn't count mixed content & CORS as network failures, which seems odd to me. |
That specification seems to lack proper integration in the appropriate layers. |
It would be great for this issue to verify the implementations of |
Haven't we already designed the primitive? It's |
@domenic it doesn't help if you ignore everything from #103 (comment) onward or pretend it's not meaningful. |
I'm not. Everything from then onward seems to be talking about breaking down responses into two categories: those that are OK and those that are not OK. That's the primitive. Everything on top of that is sugar. |
No, e.g., @jakearchibald pointed out not having this would not allow for atomic cache operations. |
I think this is coming down to different definitions of primitive, which is what I found confusing. (E.g. a primitive would not be "perform atomic cache operations based on the OK-ness". You would combine the two primtives, "mutex" and "OK-ness", to be able to do atomic operations on OK-ness or on any other thing.) At this point I guess there's nothing further to be clarified so I'll bow out. |
Developer request for this http://tjvantoll.com/2015/09/13/fetch-and-errors/ |
Well, I was trying to show that the default behavior of Honestly I don't think this is that big of a deal, as after 5 minutes of Googling I knew what I needed to do, and I know how to use the |
Having thought about this a bit more I agree with @domenic that the Cache API would need to expose that other primitive. That way you can e.g., require a certain header or a specific status. I don't think we should add anything special to either the Cache API or Request for this particular case and I also hope we continue to avoid divergence between the Cache API and Request objects. |
Something like:
…which would cause
fetch
to reject ifresponse.ok
is false. Default value would beany
. It could be a boolean, but a value like this means we could let the developer require a specific status code.This would always reject with no-cors requests to avoid x-origin leakage.
The text was updated successfully, but these errors were encountered: