TarkyT
tRPC11mo ago
2 replies
Tarky

Catch the error on trycatch and show the message

Hello, I am throwing a TRPCError inside my procedure

throw new TRPCError({
                    code: "BAD_REQUEST",
                    message: "Not enough credits",
                });


How can I get this message in my react onSubmit handler?

async function onSubmit(values: z.infer<typeof formSchema>) {
        try {
            await createImage({
                prompt: values.prompt,
                type: values.type,
            });

            router.refresh();
        } catch (cause) {
            console.log(cause);
            toast({
                title: "Error",
                description:
                    "An error occurred while creating your image. Please try again.",
            });
        }
    }
`
Was this page helpful?