ZSA not returning success or error information in response
Hello.
I'm currently using ZSA and noticed that I'm unable to capture either success or error results. I created an action that intentionally returns an error, but it’s triggering the onSuccess event instead of onError. Moreover, no error information or message is provided. I also tested with a successful response, but the data parameter is returning as undefined.
```ts
// Success testing
export const buyPlanAction = authedProcedure
.createServerAction()
.input(
z.object({
planId: z.string(),
periodId: z.string(),
couponId: z.string().nullable(),
paymentMethod: z.nativeEnum(OrderPaymentMethodEnum),
}),
)
.handler(async ({ input, ctx }) => {
return { success: 'Testando' }
})
```
```ts
// Error testing
export const buyPlanAction = authedProcedure
.createServerAction()
.input(
z.object({
planId: z.string(),
periodId: z.string(),
couponId: z.string().nullable(),
paymentMethod: z.nativeEnum(OrderPaymentMethodEnum),
}),
)
.handler(async ({ input, ctx }) => {
throw new Error("teste")
})
```
```ts
export function CardComponent({ plan, periodId, handleClearCheckout }: CardContentProps) {
const { isPending, execute } = useServerAction(buyPlanAction, {
onError: ({ err }) => {
// NEVER HITS THIS POINT
toast.error(err.message)
},
onSuccess: ({ data: { success } }) => {
console.log('success', success) // ERROR
toast.success('Compra realizada com sucesso!')
},
})
const handleBuyPlan = async () =>
await execute({
planId: plan.id,
periodId: selectedPeriodId,
couponId: null,
paymentMethod: OrderPaymentMethodEnum.PIX,
})
// More code here...
```
**I am using Next.js 15.0.2 and ZSA 0.6.0**

1 条评论