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

后端 未结 7 2135
予麋鹿
予麋鹿 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

    You should use 4xx for a client error if the client can modify the request to get around the error. Use a 5xx for a server error that the client can't really work around.

    Product sold out would be a server error. The client can't modify the request in some fashion to get around the error. You could switch to another product but wouldn't that be a new request?

    User maximum order limit reached is also a server error. Nothing the client can do to work around that error.

    Credit card transaction failure would be a client error. The client could resubmit the request with a different payment method or credit card number to work around the error.

提交回复
热议问题