Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZSA not returning success or error information in response #230

Open
Snarloff opened this issue Nov 6, 2024 · 1 comment
Open

ZSA not returning success or error information in response #230

Snarloff opened this issue Nov 6, 2024 · 1 comment

Comments

@Snarloff
Copy link

Snarloff commented Nov 6, 2024

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
Copy link
Author

Snarloff commented Nov 6, 2024

I also tested it without using a procedure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant