What is the appropriate HTTP status code response for a general unsuccessful request (not an error)?

后端 未结 7 2087
予麋鹿
予麋鹿 2020-12-02 07:18

I\'m creating a RESTful API that will process a number of user interactions, including placing orders using stored credit cards.

In the case of a successful order, I

7条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-02 07:54

    I know this question is old, but I came up with the very same question today. If my user runs out of credits, what status code should my REST API return?

    I tend to lean towards 402 Payment Required:

    According to Wikipedia:

    Reserved for future use. The original intention was that this code might be used as part of some form of digital cash or micropayment scheme, but that has not happened, and this code is not usually used. Google Developers API uses this status if a particular developer has exceeded the daily limit on requests.

    And indeed they do:

    PAYMENT_REQUIRED (402)

    • A daily budget limit set by the developer has been reached.
    • The requested operation requires more resources than the quota allows. Payment is required to complete the operation.
    • The requested operation requires some kind of payment from the authenticated user.

提交回复
热议问题