IdoPesok / zsa

https://zsa.vercel.app
MIT License
810 stars 24 forks source link

ZSA not returning success or error information in response #230

Open Snarloff opened 3 hours ago

Snarloff commented 3 hours ago

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.

// 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' }
  })
// 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")
  })
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

image

Snarloff commented 3 hours ago

I also tested it without using a procedure.