Error code for invalid POST parameter

What is the correct error code when a POST request has an invalid parameter? Let's say: a form accepts data for an event, but the date indicated was in the past; or the form accepts the data for registering the user, but the specified name is a number or any invalid name of the person.

+6
source share
2 answers

11.2. 422 Non-process organization

Status code 422 (raw entity) means server
understands the content type of the request object (therefore, 415 (Unsupported media type) is not suitable), and the syntax of the request object is correct (thus 400 (invalid request)
status code is not appropriate), but could not process the contained instructions. For example, this error condition may occur if the XML body of the request contains well-formed (i.e., syntactically correct), but
semantically erroneous XML instructions.

(From RFC 4918 )

+5
source

I personally would choose: 400 Bad Request

the error should be in the 4xx range, which represents the client’s errors, since the client is responsible for transmitting reliable data.

In any case, you can look at the list of standard HTTP response codes and choose the one that seems to fit your needs.

0
source

Source: https://habr.com/ru/post/899689/


All Articles