How to handle Errors from server actions into client side component #73399
Unanswered
suhejbfejziu
asked this question in
App Router
Replies: 2 comments 1 reply
-
You can set cookies on server side, check them on client, and display message. |
Beta Was this translation helpful? Give feedback.
0 replies
-
The problem is that server actions, as I see it, expect you to handle your business scenarios, so that your server action always succeeds, and can communicate back to the client, what the result was. You are literally triggering server side code through calling a server action, and a failure on that, is too open ended. Instead of throwing an error, you could return a object, with a given shape that, your client can interpret as necessary. |
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
-
I'm currently using external APIs to perform mutations with server actions. However, when a mutation occurs, I need to display a message or show a toast notification in the client component. The issue arises when I throw an error within the server actions—it consistently results in a 500 Internal Server Error. This doesn't seem like the best approach for handling errors. Should I consider switching to something like TanStack Query for mutations, or is there a better way to handle errors and communicate them effectively to the client?
Beta Was this translation helpful? Give feedback.
All reactions