Conversation
|
So basically, the behavior is identical to fetch, except that schemas can be used to handle empty bodies as The only thing I'm not sure of is the 204 case. Is throwing better than returning an empty string like we did in 1.x? If so, how should users handle responses where they expect either JSON or an empty 204? They could One solution could be a dedicated Another solution could be an |
|
I think throwing is still the better default for For endpoints that intentionally return either JSON or const response = await ky(url);
if (response.status === 204) {
return undefined;
}
return response.json();That avoids needing to catch a parse error just to inspect status, and it keeps plain I think a dedicated |
This makes the default
.json()contract simpler and more predictable.Returning
undefinedfor empty200/204responses was type-corrrect, but it pushed a rare edge case into every normal JSON call site by widening.json<T>()toPromise<T | undefined>. That made the common path worse for everyone just to accommodate a response shape that is usually either a server bug or a different API contract.This change restores a cleaner boundary:
.json()means “parse JSON”Promise<T>That is better because it gives us strict runtime behavior, simple types, and no global
| undefinedpollution.