根据iana.org:
4xx: Client Error - The request contains bad syntax or cannot be fulfilled
5xx: Server Error - The server failed to fulfill an apparently valid request
我认为 4xx 状态代码中的任何一个都不应作为对内部服务器错误或迁移的响应,或者......客户端没有责任或用户的输入需要重新检查。除非涉及用户的预填充数据,例如用户的包可能不允许他在预定和已知日期之后访问该数据,在这种特定情况下它可能是有效的 403 Forbidden 作为@Bari确实建议了。
我不是专家,但我认为当服务器拒绝或决定将端点数据视为损坏或无效时,这将取决于下一步应该做什么。我看到 3 个可能的情况:
1. 预计这会以某种方式得到解决,客户
应该被邀请请求回来,但在未来的某个时刻 ==> 503 (Service Unavailable):
503 (Service Unavailable)
status code indicates that the server
is currently unable to handle the request due to a temporary overload
or scheduled maintenance, which will likely be alleviated after some
delay. The server MAY send a Retry-After header field
(Section 7.1.3) to suggest an appropriate amount of time for the
client to wait before retrying the request.
2. 出了点问题,这不是客户的责任,但有另一种访问数据的方法,可能遵循特定流程或发送更多详细信息 ==> 510 Not Extended
2. 服务器无法满足请求,但有另一种方法要求它包含更多详细信息。 示例:当请求的数据损坏时,服务器错误响应可能包括旧(或未保存、未版本化)版本的列表,并希望客户端更具体地说明哪个版本选择以便可以获取它而不是损坏的一个 ==> 510 Not Extended
510 Not Extended
The policy for accessing the resource has not been met in the
request. The server should send back all the information necessary
for the client to issue an extended request. It is outside the scope
of this specification to specify how the extensions inform the
client.
If the 510 response contains information about extensions that were
not present in the initial request then the client MAY repeat the
request if it has reason to believe it can fulfill the extension
policy by modifying the request according to the information provided
in the 510 response. Otherwise the client MAY present any entity
included in the 510 response to the user, since that entity may
include relevant diagnostic information.
- 案例 2 已更新为包含一个示例,恕我直言,它可能适合这种情况。但我又不是任何专家,我可能是
错了
3. 没有其他方法,没有什么可期待的,或者没有其他情况 ==> 500 应该是好的
500 (Internal Server Error)
status code indicates that the server
encountered an unexpected condition that prevented it from fulfilling
the request.