Skip to content

Open-source status page, incident response and uptime monitoring

fix: error message (#525)

Maximilian Kaskeaea8a83c4d28
diff --git a/apps/web/src/app/status-page/[domain]/_components/actions.ts b/apps/web/src/app/status-page/[domain]/_components/actions.ts
index 7535af157..ee07379d1 100644
--- a/apps/web/src/app/status-page/[domain]/_components/actions.ts
+++ b/apps/web/src/app/status-page/[domain]/_components/actions.ts
@@ -25,7 +25,9 @@ export async function handleSubscribe(formData: FormData) {
if (!validatedFields.success) {
const fieldErrors = validatedFields.error.flatten().fieldErrors;
- throw new Error(fieldErrors?.email?.[0] || "Invalid form data");
+ return {
+ error: fieldErrors?.email?.[0] || "Invalid form data",
+ };
}
const { slug } = validatedFields.data;
@@ -40,7 +42,9 @@ export async function handleSubscribe(formData: FormData) {
.get();
if (!pageData) {
- throw new Error("Page not found");
+ return {
+ error: "Page not found",
+ };
}
const alreadySubscribed = await db
@@ -55,7 +59,9 @@ export async function handleSubscribe(formData: FormData) {
.get();
if (alreadySubscribed) {
- throw new Error("Already subscribed");
+ return {
+ error: "Already subscribed",
+ };
}
const token = crypto.randomUUID();
diff --git a/apps/web/src/app/status-page/[domain]/_components/subscribe-button.tsx b/apps/web/src/app/status-page/[domain]/_components/subscribe-button.tsx
index f90dae8a7..47ada0674 100644
--- a/apps/web/src/app/status-page/[domain]/_components/subscribe-button.tsx
+++ b/apps/web/src/app/status-page/[domain]/_components/subscribe-button.tsx
@@ -44,21 +44,19 @@ export function SubscribeButton({ slug }: Props) {
<form
className="grid gap-2"
action={async (formData) => {
- try {
- await handleSubscribe(formData);
+ const res = await handleSubscribe(formData);
+ if (res?.error) {
toast({
- title: "Success",
- description: "Please confirm your email.",
+ title: "Something went wrong",
+ description: res.error,
+ variant: "destructive",
});
- } catch (e) {
- if (e instanceof Error) {
- toast({
- title: "Something went wrong",
- description: e.message,
- variant: "destructive",
- });
- }
+ return;
}
+ toast({
+ title: "Success",
+ description: "Please confirm your email.",
+ });
}}
>
<Label htmlFor="email">Email</Label>