Closed AdamFoskit closed 3 years ago
Looks like the issue may be here.
try {
res = await fetchClient(key, options);
const body = await res.json();
payload = {
body,
ok: res.ok,
headers: headersToObject(res.headers),
status: res.status,
};
} catch (requestError) {
// eslint-disable-next-line no-console
console.error(requestError);
error = requestError;
}
We're expecting the response to have a body retrievable by .json()
We should probably check if the response is ok
, if not, get the error from res.text()
and return the rest of the payload.
@jgolden17 Yeah, that looks like the problem.
This issue is stale because it has been open 30 days with no activity.
This issue is stale because it has been open 30 days with no activity.
this should be resolved by https://github.com/americanexpress/fetchye/pull/38
🐞 Bug Report
If an API call has a response body of undefined, the
useFetchye
hook'sdata
returned is undefined, and does not provide thestatus
orheaders
from the response.To Reproduce
Use the
useFetchye
hook to query an API that returns an undefinedbody
. (Possible forstatus
201 and 204.)Expected behavior
The
data
returned from theuseFetchye
hook should always contain thestatus
andheaders
when there is a response from the API call.Screenshots
Console log of output response from
useFetchye
hook for a response with an undefinedbody
.Console log of output for the
fetch
for the same API call (before .json() was called on the response)System information
Additional context