How to return and map external service errors to fields in a Next.js Server Component action? #1708
Unanswered
PawelM-DDH
asked this question in
Q&A
Replies: 1 comment
-
Also struggling with a similar issue but using tanstack start |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have a problem with returning errors. In a function like
serverValidate
using ZOD, all variables might be valid, but later in theaction
function I send a database query to subscribe an email to the newsletter. If that email already exists, I want to return an error for that field saying that this email already exists.Is there a good practice for this? Should the error formats match those from ZOD? Does
tanstack/react-form
have any helper function to prepare such an error?I prepared an example: https://codesandbox.io/p/devbox/boring-hoover-sjlvcc
The only solution I came up with is returning something like ServerFormState in this case, or for example throw new ServerValidateError. But then it`s tricky to handle the types properly. Is there any other approach for this?
Does anyone have any cool examples of large applications with server components Next.js with tanstack/react-form on GitHub?
Beta Was this translation helpful? Give feedback.
All reactions