Skip to content

Commit bf7e8e7

Browse files
authored
fix(fetch): always set data field, even on status.ok == false (#7)
1 parent 6aa717d commit bf7e8e7

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/fetch.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,12 @@ export async function fetch<T>(
3333
const resp = await fetchRaw(url, init);
3434
const contentType = resp.headers.get("content-type") || "";
3535

36-
if (resp.ok) {
37-
// Parse the response as JSON if the content type is JSON
38-
if (contentType.includes("application/json")) {
39-
data = await resp.json();
40-
} else {
41-
// Otherwise, return however the response was read
42-
data = (await resp.text()) as unknown as T;
43-
}
36+
// Parse the response as JSON if the content type is JSON
37+
if (contentType.includes("application/json")) {
38+
data = await resp.json();
39+
} else {
40+
// Otherwise, return however the response was read
41+
data = (await resp.text()) as unknown as T;
4442
}
4543

4644
return {

0 commit comments

Comments
 (0)