简体   繁体   English

进程未运行的最佳HTTP错误代码?

[英]An optimum HTTP error code for process not running?

I am in process of building a rest server, which will be called to abort a long running process by client. 我正在构建一个休息服务器,它将被调用以中止客户端长时间运行的进程。

/abort/{processID}

Now if process with processID is not found, I am returning 404 Not Found 现在,如果找不到processID进程,我将返回404 Not Found

However if the process has already been completed/is not running, then what shall be correct HTTP Error code for the same? 但是,如果进程已经完成/未运行,那么什么是正确的HTTP错误代码呢?

406 Not Acceptable is relevant to Accept header (and hence I think I shall not used). 406 Not Acceptable与Accept标题相关(因此我认为我不会使用)。

400 Bad Request appears to be too generic. 400 Bad Request似乎过于通用。

Seeking suggestions on which header will be optimum for it? 寻求关于哪个标题最适合它的建议?

Short answer 简短的回答

Here are some reasonable options that may suit you: 以下是一些可能适合您的合理选项:

  • 404 Not Found 404未找到
  • 410 Gone 410已经走了
  • 409 Conflict 409冲突
  • 403 Forbidden 403禁止

The right choice relies on the semantics of process has already been completed/is not running : 正确的选择依赖于进程的语义已经完成/未运行

  • If the process no longer exists, consider 404 or 410 , depending on whether the condition is permanent or not. 如果该过程不再存在,请考虑404410 ,具体取决于条件是否为永久性。
  • If a process can be found with a given id, but the attempt to abort this process cannot be completed due to a conflict with the current state of the process, you could go for 409 . 如果可以找到具有给定id的进程,但由于与进程的当前状态冲突而无法完成中止此进程的尝试,则可以转到409
  • If the operation is forbidden for other reasons, choose 403 . 如果由于其他原因禁止操作,请选择403

The process no longer exists 该过程不再存在

If the process no longer exists, you could choose between 404 and 410 , depending on whether the condition is (or it is possible to determine whether the condition is) permanent or not. 如果该过程不再存在,您可以在404410之间进行选择,具体取决于条件是否(或者可以确定条件是否为永久性)。

See the following quotes from the RFC 7231 : 请参阅RFC 7231中的以下引用:

6.5.4. 6.5.4。 404 Not Found 404未找到

The 404 (Not Found) status code indicates that the origin server did not find a current representation for the target resource or is not willing to disclose that one exists. 404 (未找到)状态代码表示源服务器没有找到目标资源的当前表示,或者不愿意透露存在该目标资源。 A 404 status code does not indicate whether this lack of representation is temporary or permanent; 404状态代码并不表示这种缺乏代表性是暂时的还是永久性的; the 410 (Gone) status code is preferred over 404 if the origin server knows, presumably through some configurable means, that the condition is likely to be permanent. 如果原始服务器通过某些可配置方式知道该条件可能是永久性的,则410 (Gone)状态代码优先于404 [...] [...]

6.5.9. 6.5.9。 410 Gone 410已经走了

The 410 (Gone) status code indicates that access to the target resource is no longer available at the origin server and that this condition is likely to be permanent. 410 (Gone)状态代码表示在源服务器上不再可以访问目标资源,并且该条件可能是永久性的。 If the origin server does not know, or has no facility to determine, whether or not the condition is permanent, the status code 404 (Not Found) ought to be used instead. 如果源服务器不知道或无法确定条件是否是永久性的,则应该使用状态代码404 (未找到)。 [...] [...]

The process exists, but the operation causes a conflict 该过程存在,但操作会导致冲突

If the process exists, 404 or 410 are not the good choices. 如果该过程存在,则404410不是好的选择。

If the attempt to abort an existing process cannot be completed due to a conflict with the current state of the process, you should consider 409 along with a payload that describes the reason of the conflict. 如果由于与进程的当前状态冲突而无法完成中止现有进程的尝试,则应考虑409以及描述冲突原因的有效负载。

See the quote: 看报价:

6.5.8. 6.5.8。 409 Conflict 409冲突

The 409 (Conflict) status code indicates that the request could not be completed due to a conflict with the current state of the target resource. 409 (冲突)状态代码表示由于与目标资源的当前状态冲突而无法完成请求。 This code is used in situations where the user might be able to resolve the conflict and resubmit the request. 此代码用于用户可能能够解决冲突并重新提交请求的情况。 The server SHOULD generate a payload that includes enough information for a user to recognize the source of the conflict. 服务器应该生成一个有效载荷,其中包含足够的信息供用户识别冲突源。 [...] [...]

The process exists, but the operation is forbidden for some reason 该过程存在,但由于某种原因禁止该操作

One last option is 403 . 最后一个选项是403 This status code is frequently used for authorization problems, when the credentials are valid, but they are insufficient to authorize the request. 当凭证有效时,此状态代码经常用于授权问题,但它们不足以授权请求。

However 403 is much broader than that and could be used to indicate that a request is forbidden for reasons unrelated to the credentials . 然而, 403比这更广泛,并且可以用于指示由于与凭证无关的原因而禁止请求。 Just be sure you provide a payload that describes why the operation is forbidden. 请确保提供有效负载, 说明禁止操作的原因

See the quote: 看报价:

6.5.3. 6.5.3。 403 Forbidden 403禁止

The 403 (Forbidden) status code indicates that the server understood the request but refuses to authorize it. 403 (禁止)状态代码表示服务器理解请求但拒绝授权。 A server that wishes to make public why the request has been forbidden can describe that reason in the response payload (if any). 希望公开请求被禁止的服务器可以在响应有效负载中描述该原因(如果有的话)。

If authentication credentials were provided in the request, the server considers them insufficient to grant access. 如果请求中提供了身份验证凭据,则服务器认为它们不足以授予访问权限。 The client SHOULD NOT automatically repeat the request with the same credentials. 客户端不应该使用相同的凭据自动重复请求。 The client MAY repeat the request with new or different credentials. 客户端可以使用新的或不同的凭据重复请求。 However, a request might be forbidden for reasons unrelated to the credentials. 但是,出于与凭证无关的原因,可能会禁止请求。

An origin server that wishes to "hide" the current existence of a forbidden target resource MAY instead respond with a status code of 404 (Not Found). 希望“隐藏”禁止目标资源的当前存在的源服务器可以以状态代码404 (未找到)来响应。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM