代码之家  ›  专栏  ›  技术社区  ›  Nima Mohammadi

删除非空资源时出现正确的HTTP错误

  •  0
  • Nima Mohammadi  · 技术社区  · 9 年前

    我使用204(无内容)表示服务器已完成文件夹的删除请求,对于无法找到文件夹的情况,使用404表示。如果为非空文件夹发出删除谓词,我想发出一个错误。对于这种情况,正确的HTTP响应状态代码是什么?

    1 回复  |  直到 9 年前
        1
  •  0
  •   ivo    9 年前

    我认为正确的答案是409冲突。

    The request could not be completed due to a conflict with the current state of 
    the resource. This code is only allowed in situations where it is expected 
    that the user might be able to resolve the conflict and resubmit the request. 
    The response body SHOULD include enough information for the user to recognize 
    the source of the conflict. Ideally, the response entity would include enough 
    information for the user or user agent to fix the problem; however, that might 
    not be possible and is not required.
    

    http://www.restapitutorial.com/httpstatuscodes.html 表示只要满足请求会导致资源冲突,就应该使用409。重复条目和在不支持级联删除时删除根对象是两个示例。

    推荐文章