Should i return a 400 status code for invalid server side input validation?
Unanswered
Sirex woodwasp posted this in #help-forum
Sirex woodwaspOP
in the sample code provided at https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions-and-mutations#server-side-validation-and-error-handling, we return early if the form data is invalid and set the appropriate error messages (line 17).
however the response automatically has a status code of 200 even if an error has occurred. should i respond with an error status code like 400?
if yes, how can i do it?
however the response automatically has a status code of 200 even if an error has occurred. should i respond with an error status code like 400?
if yes, how can i do it?
1 Reply
@Sirex woodwasp in the sample code provided at https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions-and-mutations#server-side-validation-and-error-handling, we return early if the form data is invalid and set the appropriate error messages (line 17).
however the response automatically has a status code of 200 even if an error has occurred. should i respond with an error status code like 400?
if yes, how can i do it?
You cannot set the status code of server actions, so no, you cannot even do it, let alone whether you should do it