From 9681d51a084322f213f0e3a81b58ff77d7617cd4 Mon Sep 17 00:00:00 2001 From: gbuomprisco Date: Fri, 1 Nov 2024 14:46:29 +0800 Subject: [PATCH] Create team: Improve error handling when creating team. --- .../src/components/create-team-account-dialog.tsx | 6 +++--- .../server/actions/create-team-account-server-actions.ts | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/features/team-accounts/src/components/create-team-account-dialog.tsx b/packages/features/team-accounts/src/components/create-team-account-dialog.tsx index 2ce6a3008..0df61e8b0 100644 --- a/packages/features/team-accounts/src/components/create-team-account-dialog.tsx +++ b/packages/features/team-accounts/src/components/create-team-account-dialog.tsx @@ -76,9 +76,9 @@ function CreateOrganizationAccountForm(props: { onClose: () => void }) { data-test={'create-team-form'} onSubmit={form.handleSubmit((data) => { startTransition(async () => { - try { - await createTeamAccountAction(data); - } catch { + const { error } = await createTeamAccountAction(data); + + if (error) { setError(true); } }); diff --git a/packages/features/team-accounts/src/server/actions/create-team-account-server-actions.ts b/packages/features/team-accounts/src/server/actions/create-team-account-server-actions.ts index 64d85a237..a741c2049 100644 --- a/packages/features/team-accounts/src/server/actions/create-team-account-server-actions.ts +++ b/packages/features/team-accounts/src/server/actions/create-team-account-server-actions.ts @@ -31,7 +31,9 @@ export const createTeamAccountAction = enhanceAction( if (error) { logger.error({ ...ctx, error }, `Failed to create team account`); - throw new Error('Error creating team account'); + return { + error: true, + }; } logger.info(ctx, `Team account created`);