How to change server actions error status code?
Answered
Fire ant posted this in #help-forum
Fire antOP
My logic using server actions were like
I got 500 error on network tab if it throws error, is that normal? Can i change it to 403 or something?
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
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
1 Reply
@Fire ant My logic using server actions were like
tsx
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?
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
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
Answer