What's the most appropriate HTTP status code for an “item not found” error page

前端 未结 6 2069
轮回少年
轮回少年 2020-12-13 16:41

I\'m curious what\'s the most appropriate HTTP status code for an \"item does not exist\" page.

If the page itself doesn\'t exist, I\'ll obviously use 404. However,

相关标签:
6条回答
  • 2020-12-13 17:10

    That's depending if userid is a resource identifier or additional parameter. If it is then it's ok to return 404 if not you might return other code like

    400 (bad request) ‐ indicates a bad request
    or
    412 (Precondition Failed) e.g. conflict by performing conditional update

    More info in free InfoQ Explores: REST book.

    0 讨论(0)
  • 2020-12-13 17:12

    204:

    No Content.” This code means that the server has successfully processed the request, but is not going to return any content

    https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/204

    0 讨论(0)
  • 2020-12-13 17:24

    A 404 return code actually means 'resource not found', and applies to any entity for which a request was made but not satisfied. So it works equally-well for pages, subsections of pages, and any item that exists on the page which has a specific request to be rendered.

    So 404 is the right code to use in this scenario. Note that it doesn't apply to 'server not found', which is a different situation in which a request was issued but not answered at all, as opposed to answered but without the resource requested.

    0 讨论(0)
  • 2020-12-13 17:28
    /**
    * {@code 422 Unprocessable Entity}.
    * @see <a href="https://tools.ietf.org/html/rfc4918#section-11.2">WebDAV</a>
    */
    UNPROCESSABLE_ENTITY(422, "Unprocessable Entity")
    
    0 讨论(0)
  • 2020-12-13 17:30

    404 is just fine. HTTP/1.1 Status Code Definitions from RFC2616

    0 讨论(0)
  • 2020-12-13 17:31

    Getting overly clever with obscure-er HTTP error codes is a bad idea. Browsers sometimes react in unhelpful ways that obfuscate the situation. Stick with 404.

    0 讨论(0)
提交回复
热议问题