ky icon indicating copy to clipboard operation
ky copied to clipboard

Should `status = 0` be considered `ok` for `mode: no-cors`-requests?

Open ulken opened this issue 5 years ago • 5 comments

According to the WHATWG Spec., status should be set to 0 for a so called opaque response stemming from a mode: "no-cors"-request. Interestingly enough, it's not considered an "OK" response in regards to response.ok (only includes 2xx).

Regardless, should 0 be treated as OK for no-cors-requests? I.e. should ky not throw an HTTPError in such cases? If it indeed should, is there/can we provide some sort of mechanism to treat a status code as an OK response?

ulken avatar Dec 10 '20 12:12 ulken

Would be a good idea!

yovanoc avatar Dec 11 '20 09:12 yovanoc

Doing this makes sense to me. But I think it could be confusing for Ky to succeed with a response where response.ok is false.

To me, the real solution is to fix https://github.com/whatwg/fetch so that response.ok correctly reflects the meaning of the response status. Could you file an issue over there?

sholladay avatar Dec 31 '20 18:12 sholladay

Sure, will do. Thanks!

ulken avatar Jan 11 '21 21:01 ulken

Seems to be a no-go. See why.

I think you can close this.

ulken avatar Jan 20 '21 07:01 ulken

Oy, that thread makes me sad for the web. Well, thanks for trying.

I guess it's on library authors to wallpaper over this issue. Domenic's solution of !res.ok && res.type !== 'opaque' looks reasonable to me. I'm in favor of implementing it, so long as it's well documented (i.e. consider how this impacts the explanation of HTTPError and the throwHttpErrors option and everything else).

sholladay avatar Jan 24 '21 03:01 sholladay