server action error handling - status 400/500 not being caught in try/catch
Answered
British Shorthair posted this in #help-forum
British ShorthairOP
I have an API fetch as a server action, and I am confused why when the request returns a
500 or 400 status code, it does not get caught in the try/catch catch block? You can't return new Error either.7 Replies
@British Shorthair I have an API fetch as a server action, and I am confused why when the request returns a `500` or `400` status code, it does not get caught in the `try/catch` catch block? You can't return `new Error` either.
take a look at how to handle errors in server actions: https://joulev.dev/blogs/throwing-expected-errors-in-react-server-actions
If you don't want to do it like that, you can still use safe-actions: https://next-safe-action.dev/
If you don't want to do it like that, you can still use safe-actions: https://next-safe-action.dev/
British ShorthairOP
the joulev.dev site dont work for me
@B33fb0n3 maybe this helps
British ShorthairOP
lol thank you 🙂
happy to help 🙂 . Please mark solution
British ShorthairOP
ugh, doesn't entirely work with SSR. server actions are TRASH