Skip to content

Commit

Permalink
add try catch
Browse files Browse the repository at this point in the history
  • Loading branch information
tsusdere committed Oct 27, 2023
1 parent 5c1fcdf commit 4c81700
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/fetch-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,14 @@ export default function fetchWrapper(
async function getResponseData(response: Response) {
const contentType = response.headers.get("content-type");
if (/application\/json/.test(contentType!)) {
return response.json();
// In the event that we get an empty response body we fallback to
// using .text(), but this should be investigated since if this were
// to occur in the GitHub API it really should not return an empty body.
try {
return response.json();
} catch (e) {
return response.text();
}
}

if (!contentType || /^text\/|charset=utf-8$/.test(contentType)) {
Expand Down

0 comments on commit 4c81700

Please sign in to comment.