Add to cart with AJAX causes error 422 if not enough inventory, but not with form submit

6 0 1

I'm creating an AJAX add to cart script and I find it curious that if I only have 5 of a product available then I can add a quantity of 50 to my cart without AJAX with no problems or errors at all—the overage simply gets taken care of during checkout. However, with AJAX, I end up with a thrown console error, the products don't get added to the cart in any quantity, and error handling is left completely up to me instead of being handled by the checkout.


Why is there such an inconsistency in the AJAX API? It would be great (and consistent) if the API would just let me add as many products to the cart as I want and then handle inventory issues during checkout in both scenarios—with and without AJAX.