executeAsync should throw errors #240
Replies: 2 comments 12 replies
-
Hmm, I understand your point, but calling the action directly doesn't throw errors either. Right now you can set Then, for instance, how would you handle validation errors when using |
Beta Was this translation helpful? Give feedback.
-
Of course, using react actions has numerous limitations. That's why we use next-safe-action.
I prefer to use onError callback. However executeAsync could return a custom extended Error just like zod does.
Great, throw server errors inside handleReturnedServerError at the client level solves the problem. I believe the question now is whether it is worth making this a standard behavior in next-safe-action. I believe it would be more intuitive. |
Beta Was this translation helpful? Give feedback.
-
It is intuitively expected that executeAsync will throw an error rather than resolving the promise with a
{ serverError: "message" }
object.Without rejection, the implementation with libs like react-hook-form does not produce the expected effects, as formState.isSubmitSuccessful will always be true even if it is not successful.
Consider react-query's mutateAsync:
https://tanstack.com/query/v4/docs/framework/react/guides/mutations#promises
Beta Was this translation helpful? Give feedback.
All reactions