【问题标题】:Indicating Invalid Value with Reason用原因指示无效值
【发布时间】:2023-03-10 12:25:01
【问题描述】:

我正在设计一个端点,客户端将点击该端点向应用程序注册租户;这些租户表示为子域 (<subdomain>.alex.com)。我想保留所有长度

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.

【问题讨论】:

  • “语义错误”听起来是使用 422 的好理由。

标签: rest http-status-code-400 http-response-codes


【解决方案1】:

422 代码似乎适合您想要做的事情,但我也会考虑 403,它也可以适用。出于几个原因,我更喜欢 403 而不是 422,即 403 的代码定义表明不应该发出自动重复,甚至只是因为它是更常用的状态代码。然而,这只是我的意见。在这两种情况下,我认为服务器还应该发送一条解释问题的消息以及状态代码。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-23
    • 1970-01-01
    • 1970-01-01
    • 2016-03-14
    • 2022-01-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多