我正在设计一个客户端点击以向应用程序注册租户的端点;这些租户被表示为子域(<subdomain>.alex.com
)。我想保留长度为&lt; = 4的所有子域(例如,它们只能为选定的客户端注册)。什么是&#34;权利&#34; HTTP错误代码,如果他们选择子域&lt; = 4个字符,则返回给用户?
400似乎还可以,但我想知道是否有更好的。
一个想法是422:
422 Unprocessable Entity
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.
答案 0 :(得分:0)
422代码似乎对你想做的事情有好处,但我也会考虑403,这也适用。出于几个原因,我更喜欢403而不是422,即403状态的代码定义不应该发出自动重复,或者甚至只是因为它是更常用的状态代码。不过这只是我的意见。在这两种情况下,我认为服务器还应该发送一条消息来解释问题以及状态代码。