Skip to content

Commit f2f6483

Browse files
authored
fix: handle empty response in getCustomization function (#456)
1 parent 61fbf11 commit f2f6483

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

  • packages/donate-button-v4/src/components/widget/api

packages/donate-button-v4/src/components/widget/api/index.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,18 @@ export async function getCustomization(nonprofitId: string, code?: string) {
5656
const url = `${BASE_API_URL}/${nonprofitId}/customization${
5757
code ? `?code=${code}` : ''
5858
}`;
59-
const response: DonateFlowCustomization = await fetch(url).then(
60-
async (response) => response.json()
61-
);
59+
const response = await fetch(url).then(async (response) => {
60+
const body = await response.text();
61+
62+
if (!body) {
63+
return undefined;
64+
}
65+
66+
try {
67+
return JSON.parse(body) as DonateFlowCustomization;
68+
} catch {
69+
return undefined;
70+
}
71+
});
6272
return response;
6373
}

0 commit comments

Comments
 (0)