Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

fix: wrap in try/catch

Marc Seitzf6473cf555a0
diff --git a/components/domains/add-domain-modal.tsx b/components/domains/add-domain-modal.tsx
index 7c84aab6..3a83a609 100644
--- a/components/domains/add-domain-modal.tsx
+++ b/components/domains/add-domain-modal.tsx
@@ -219,39 +219,44 @@ export function AddDomainModal({
}
setSubmitting(true);
- const response = await fetch(
- `/api/teams/${teamId}/domains`,
- {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
+ try {
+ const response = await fetch(
+ `/api/teams/${teamId}/domains`,
+ {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({
+ domain: normalizedDomain,
+ }),
},
- body: JSON.stringify({
- domain: normalizedDomain,
- }),
- },
- );
-
- if (!response.ok) {
- const { message } = await response.json();
- setSubmitting(false);
- toast.error(message);
- return;
- }
+ );
- const newDomain = await response.json();
+ if (!response.ok) {
+ const { message } = await response.json();
+ toast.error(message);
+ return;
+ }
- analytics.capture("Domain Added", { slug: normalizedDomain });
- toast.success("Domain added successfully! 🎉");
+ const newDomain = await response.json();
- // Update local data with the new link
- onAddition && onAddition(newDomain);
+ analytics.capture("Domain Added", { slug: normalizedDomain });
+ toast.success("Domain added successfully! 🎉");
- setOpen(false);
+ // Update local data with the new link
+ onAddition && onAddition(newDomain);
- setSubmitting(false);
+ setOpen(false);
- !onAddition && window.open("/settings/domains", "_blank");
+ !onAddition && window.open("/settings/domains", "_blank");
+ } catch (error: unknown) {
+ const message =
+ error instanceof Error ? error.message : "An unknown error occurred";
+ toast.error(`Failed to add domain: ${message}`);
+ } finally {
+ setSubmitting(false);
+ }
};
// If the team is