422(无法处理的实体)状态码表示服务器理解请求实体的内容类型(因此不适用415(不支持的媒体类型)状态码),并且请求实体的语法正确(因此不适用400(错误的请求)状态码),但无法处理所包含的指令。例如,如果XML请求主体包含形式良好(即语法正确),但语义上错误的XML指令,则可能会出现此错误条件。
我可以使用这些WebDAV扩展代码来处理我的HTTP请求吗?在422的情况下,即使它不在核心HTTP代码中,我也可以使用它吗?
对于客户端错误,我应该使用400还是422?
以下是我考虑的可能的客户端错误:
1.) Invalid parameter. The client provided parameters but are found invalid. Example: I said that the userId is 1, but when I checked there's no userId of 1. Another example of invalid parameter is wrong data type.
2.) Missing required parameters
3.) Let's say I need to hash a value based on given params and it failed
4.) Blocked content is being used. Like, i want to apply for membership and i passed the userId of 1. However, userId of one is blocked / deactivated
5.) When I try to delete an entry but the entry is still being used in another table.
6.) Let's say i require a signature in my payload and the signature does not match when recalculated in the backend
7.) Let's say I have a value that counts a specific attribute like "shares" and it has reached the maximum value like 10.
etc...
更新:我检查了谷歌API错误,它们没有使用422。另一方面,Twitter使用422。我比以往任何时候都更困惑>。<虽然我认为400是更好的选择,因为它包含在RFC文档中,而422则不是。不过我可能错了。