server function error handling
Is there any error handling in server functions? Because if an RPC gets called and throws an error, it gets stringified and returned with a 200 status code.
5 Replies
Uncaught errors are handled with the ErrorBoundary component.
But inside server functions you can catch handle the error yourself.
yes but I want to throw the error again but its always status code 200
That is related to your rpc.
What is that doing?
And if you are modifying data in a db you should probably use an action instead of query
try {
return myAction()
} catch {
return new Response(…)
}
you could just return a response and set any status code you wnat
You can also get more typed errors using this
https://mediakit-taupe.vercel.app/prpc/error
https://mediakit-taupe.vercel.app/prpc/error-handling