Replies: 1 comment
-
Perfectly solve a problem that we have in mind, would love to see a way to configure error obfuscation behavior |
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.
Uh oh!
There was an error while loading. Please reload this page.
-
Goals
Make error handling in server actions simpler by throwing instances of a
PublicError
class (exported fromnext
)Currently error messages get stripped away from server actions errors: https://x.com/asidorenko_/status/1702684047879626792?s=20
Non-Goals
No response
Background
Currently error messages get stripped away from server actions errors: https://x.com/asidorenko_/status/1702684047879626792?s=20
The alternative to this proposal would be to return an object with an error field, but this is not idiomatic in JavaScript and most existing code use exceptions instead
Migrating user code to server actions with this RFC would mean replacing some
throw new Error
withthrow new PublicError
Without this proposal you would need to wrap all server actions with a
try catch
block and manually handle each error type, which would mean implementing this RFC in user code (or worse, passing all errors down to the client, possibly exposing secret data)Proposal
Add a
PublicError
error class (or a different name, see x poll) that retains its error message and properties when thrown inside a server actionThe client code can then handle these errors, in case the server action is called directly by using a
catch
block or using theuseFormStatus
hook when using theaction
propTo make error handling easier i would also suggest turning any non
PublicError
into aPublicError('Unexpected error')
so that the user will never see cryptic error messages likeThe specific error message is omitted ...
Example
Beta Was this translation helpful? Give feedback.
All reactions