Why can I not convey user-appropriate messages via throws from server actions? #76452
Unanswered
craigmcc
asked this question in
App Router
Replies: 1 comment 1 reply
-
|
you not catching the throws? and returning the message? |
Beta Was this translation helpful? Give feedback.
1 reply
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.
Uh oh!
There was an error while loading. Please reload this page.
-
I am looking at converting an old CRA-based app to NextJS 15 + React 19. In my old app, I have a bunch of database mutations (now becoming Server Actions) that would complain with thrown errors if something was wrong that the Zod schema for something did not detect. In this particular case, it's on the signup page for my app, which wants to prevent users with duplicate email addresses from signing up.
In my old app, the functional logic that checks for this (to avoid a probably incomprehensible error message about "foreign key violation" or similar to a user) throws an error that says something simple: "That email address is already in use". Simple, clear, gives the prospective user an option to do something (because we are still on the same page.
In dev mode in NextJS, it does the same thing. My sign up form does a try-catch around the logic that sets up a new user, and the catch block causes the above message to be displayed.
In prod mode, that doesn't happen. Instead, I get:
which, basically, says, the actual error cause was recorded in a server log message. That's actually true.
But what in the heck am I supposed to do for the user? What I would like is an option to actually return the message in the "throws" clause, since in my app those are purposely user directed (I also log more details on the server side, but that's not an issue that the user cares about).
Can I please have an option that tells NextJS in production mode to pass through any messages from a thrown error? I am totally fine if this is not the default -- but I would really rather not have to reinvent the entire relationship between client and server just to work around this NextJS limitation.
Beta Was this translation helpful? Give feedback.
All reactions