From aa20a803d0c5b3bf70b26a7ac8b46f8abfaa0325 Mon Sep 17 00:00:00 2001 From: Chuma McPhoy Date: Thu, 3 Oct 2024 10:47:15 +0200 Subject: [PATCH] fix(SW-360): better handleSubmit error handling --- components/Forms/Register/index.tsx | 14 +++++++++++--- server/trpc.ts | 14 -------------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/components/Forms/Register/index.tsx b/components/Forms/Register/index.tsx index 1b152008f..9e5a05f39 100644 --- a/components/Forms/Register/index.tsx +++ b/components/Forms/Register/index.tsx @@ -52,11 +52,19 @@ export default function Form({ link, subtitle, title }: RegisterFormProps) { const zipCode = intl.formatMessage({ id: "Zip code" }) async function handleSubmit(data: RegisterSchema) { - const result = await registerUser(data) - if (!result.success) { + try { + const result = await registerUser(data) + if (result && !result.success) { + toast.error(intl.formatMessage({ id: "Something went wrong!" })) + } + } catch (error) { + // The server-side redirect will throw an error, which we can ignore + // as it's handled by Next.js. + if (error instanceof Error && error.message.includes("NEXT_REDIRECT")) { + return + } toast.error(intl.formatMessage({ id: "Something went wrong!" })) } - // No need to handle success case here, as the redirect happens server-side. } return ( diff --git a/server/trpc.ts b/server/trpc.ts index ccf49a3ec..4dccbb7f5 100644 --- a/server/trpc.ts +++ b/server/trpc.ts @@ -140,20 +140,6 @@ export const serverActionProcedure = t.procedure.experimental_caller( }) ) -export const hotelServiceServerActionProcedure = serverActionProcedure.use( - async (opts) => { - const { access_token } = await fetchServiceToken(["hotel"]) - if (!access_token) { - throw internalServerError("Failed to obtain service token") - } - return opts.next({ - ctx: { - serviceToken: access_token, - }, - }) - } -) - export const profileServiceServerActionProcedure = serverActionProcedure.use( async (opts) => { const { access_token } = await fetchServiceToken(["profile"])