Is returning HTTP 409 appropriate for a validation check?

后端 未结 5 1173
-上瘾入骨i
-上瘾入骨i 2020-12-17 19:06

I have a service where some validation rules must be checked before a particular operation should be able to take place.

For instance, the client should not generate

5条回答
  •  北荒
    北荒 (楼主)
    2020-12-17 19:37

    While it is defined in a proposed standard still, 422 Unprocessable Entity is an appropriate status.

    The 422 (Unprocessable Entity) status code means the server understands the content type of the request entity (hence a 415(Unsupported Media Type) status code is inappropriate), and the syntax of the request entity is correct (thus a 400 (Bad Request) status code is inappropriate) but was unable to process the contained instructions.

    For example, this error condition may occur if an XML request body contains well-formed (i.e., syntactically correct), but semantically erroneous, XML instructions.

    References:

    • https://tools.ietf.org/html/rfc4918#section-11.2
    • http://developer.github.com/v3/#client-errors
    • https://stackoverflow.com/a/2657624/247702
    • http://en.wikipedia.org/wiki/List_of_HTTP_status_codes#4xx_Client_Error

提交回复
热议问题