fix(SW-360): better handleSubmit error handling
This commit is contained in:
committed by
Pontus Dreij
parent
540ce58446
commit
3407d48f6a
@@ -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 (
|
||||
|
||||
Reference in New Issue
Block a user