When making a cross-domain fetch one may receive a response with response.type === 'opaque'.
Currently this seems to mean (at least in Chrome) that response.ok is false even if the response succeeded.
The current spec does not appear to specify what the value for response.ok should be in this situation (see the spec here), while it does specify other values like response.status being 0). The docs on MDN also do not discuss the value in opaque cases (or that they are even a possibility).
I feel that a response.ok value of false is misleading and may catch other people out who are not aware of the meaning of opaque responses. As for what the value should be, I'm not sure. A value of true may also be equally misleading. A value of null might be better, but still has potential for issues for people naively checking for ok like most examples do.
For those just looking for a code solution, here is one way to catch this case:
if (response.type === 'opaque' || response.ok) {
return response;
} else {
// do something else
}
Thanks!
When making a cross-domain fetch one may receive a response with
response.type === 'opaque'.Currently this seems to mean (at least in Chrome) that
response.okisfalseeven if the response succeeded.The current spec does not appear to specify what the value for
response.okshould be in this situation (see the spec here), while it does specify other values likeresponse.statusbeing0). The docs on MDN also do not discuss the value in opaque cases (or that they are even a possibility).I feel that a
response.okvalue offalseis misleading and may catch other people out who are not aware of the meaning of opaque responses. As for what the value should be, I'm not sure. A value oftruemay also be equally misleading. A value ofnullmight be better, but still has potential for issues for people naively checking foroklike most examples do.For those just looking for a code solution, here is one way to catch this case:
Thanks!