Replies: 1 comment 4 replies
-
Maybe that's why Dan Abramov recommends to return the error in the body of the server action? https://twitter.com/dan_abramov/status/1654894995315253257 I've been wondering what is wrong about just try/catching them in the client component. |
Beta Was this translation helpful? Give feedback.
4 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
Currently, it's impossible to catch errors from Server Actions as
redirect
s/not-found
s are also thrown as error, which means they are caught if a Server Action (either on the server or client) is caught).Example 1:
Example 2:
Background
Current alternative is to import
isRedirectError
/isNotFoundError
from the dist bundle and check manually.Proposal
3 items:
isRedirectError
/isNotFoundError
(and others like it, e.g. revalidate) fromnext/navigation
isServerActionError
(orisNextNavigationError
), which checks forisRedirectError
/isNotFoundError
and all others like ithandleServerActionError
, which can be added to acatch
, which rethrows any navigation errors. Example code:Beta Was this translation helpful? Give feedback.
All reactions