Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP Status code for generic failure

I am looking for a correct status code to send for a gneral failure through an api.

The exact scenario is failing to add an product to a shopping cart.

The failure could happen for a large number of reasons, but i would like to return a single http code.

Which would be best?

I have been looking through them and cant see anything that exactly fits the needs here.

Some of the possible failure conditions could be:

Not enough stock to satisfy
Stock limit reached for that particular product
Product no longer available
like image 335
Marty Wallace Avatar asked Jun 05 '13 16:06

Marty Wallace


People also ask

What is a 444 error?

A 444 No Response error indicates that the server has closed the connection with no returned information from a client request.

What is a generic HTTP error?

A generic error message, given when an unexpected condition was encountered and no more specific message is suitable. 501 Not Implemented. The server either does not recognize the request method, or it lacks the ability to fulfil the request.

What is a 309 status code?

Status codes 309 through 399 are currently unassigned.

What is a 402 HTTP error?

The HTTP 402 Payment Required is a nonstandard response status code that is reserved for future use. This status code was created to enable digital cash or (micro) payment systems and would indicate that the requested content is not available until the client makes a payment.


1 Answers

If it's server error then it should be 500. If it's client error, use 400.

It's hard to be more precise than that without seeing the URI and what you do with it. For example, if "Product no longer available" is a result of GET request, then it should be 404 (not found). But if it was a POST request, then it should be 200 or 202.

For the other two, they might not be error. It could be the client has sent the correct request but the stock has been consumed by someone else, in this case server should return 409 (conflict) . If the request was for too much stock from the start, then it should just be 200/202.

If you had to have only one code, just use 400 and 200 (see above).

like image 88
imel96 Avatar answered Oct 12 '22 02:10

imel96