From 8967818fcc1668db6e7253aba32b70bfb05a0632 Mon Sep 17 00:00:00 2001 From: regalijan Date: Thu, 19 Oct 2023 16:51:17 -0400 Subject: [PATCH] Handle unexpected exceptions better --- components/AppealCard.tsx | 9 ++++++++- functions/gcloud.ts | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/components/AppealCard.tsx b/components/AppealCard.tsx index 75b6803..02b248e 100644 --- a/components/AppealCard.tsx +++ b/components/AppealCard.tsx @@ -62,9 +62,16 @@ export default function (props: AppealCardProps) { document.getElementById(`appeal_${props.id}`)?.remove(); } else { + let error; + + try { + error = ((await actionReq.json()) as { error: string }).error; + } catch { + error = "Unknown error"; + } setLoading(false); toast({ - description: ((await actionReq.json()) as { error: string }).error, + description: error, duration: 10000, status: "error", title: "Oops!", diff --git a/functions/gcloud.ts b/functions/gcloud.ts index 5de325b..1809acd 100644 --- a/functions/gcloud.ts +++ b/functions/gcloud.ts @@ -296,5 +296,5 @@ export async function sendPushNotification( }, ); - if (!notifResp.ok) throw new Error(await notifResp.json()); + if (!notifResp.ok) throw new Error(await notifResp.text()); }