Skip to content

ZSA not returning success or error information in response #230

Description

@Snarloff

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions