Skip to content

Commit

Permalink
fix: return response for non json (#5785)
Browse files Browse the repository at this point in the history
* fix: return response for non json

* chore: format

* fix: check for proper header

* Return content type from fetch mocks

---------

Co-authored-by: Aditya Hegde <[email protected]>
  • Loading branch information
mindspank and AdityaHegde authored Sep 26, 2024
1 parent 30841ab commit 0a38393
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export class DashboardFetchMocks {
ready: true,
ok: true,
json: () => this.responses.get(key),
headers: new Map([["content-type", "application/json"]]),
};
}
}
4 changes: 4 additions & 0 deletions web-common/src/runtime-client/fetchWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ export async function fetchWrapper({
signal,
});

const contentType = resp.headers?.get("content-type");
if (!contentType?.includes("application/json") && resp.ok) {
return resp;
}
const json = await resp.json();

if (resp.ok) return json;
Expand Down

1 comment on commit 0a38393

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.