HTTP status code for “no data available” from an external datasource

后端 未结 5 1651
梦谈多话
梦谈多话 2020-12-29 01:20

Scenario:

A POST request is sent to process an order that will result in data retrieval from an external datasource.

There are

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-29 01:59

    3) I agree with 503 for this

    2) Frankly I think a good argument could be made for using 204 in case 2 You can include metainfo in the header to indicate specifically what 'went wrong'. It really depends on how much you consider this case to be 'an error' at the API level.

    If the API itself is functioning as intended, and the request was to a valid endpoint, by an authenticated and authorized user and did not cause the server to malfunction, then very few of the 400 or 500 series errors would really seem to apply.

    for example, 404 usually means the URI you called does not exist, if it does exist, then using that code is misleading at least IMHO

    **10.2.5 204 No Content**
    

    The server has fulfilled the request but does not need to return an entity-body, and might want to return updated metainformation. The response MAY include new or updated metainformation in the form of entity-headers, which if present SHOULD be associated with the requested variant.

    If the client is a user agent, it SHOULD NOT change its document view from that which caused the request to be sent. This response is primarily intended to allow input for actions to take place without causing a change to the user agent's active document view, although any new or updated metainformation SHOULD be applied to the document currently in the user agent's active view.

    The 204 response MUST NOT include a message-body, and thus is always terminated by the first empty line after the header fields.

提交回复
热议问题