Next.js Discord

Discord Forum

How to change server actions error status code?

Answered
Fire ant posted this in #help-forum
Open in Discord
Fire antOP
My logic using server actions were like
if (data) {
      const count = data;
      if (count > 0) {
        throw new Error("Some error");
      }
    } else {
      throw new Error("ERROR");
    }

I got 500 error on network tab if it throws error, is that normal? Can i change it to 403 or something?
Answered by joulev
No, impossible.

You also shouldn’t throw expected errors (user errors) in server actions. See also: https://joulev.dev/blogs/throwing-expected-errors-in-react-server-actions
View full answer

1 Reply