/cart/change.js don't return Checkout Validation Rule error like /cart/add.js

/cart/change.js don't return Checkout Validation Rule error like /cart/add.js

JohnSmith6
Shopify Partner
7 2 4

I had a sample code like below

fetch('/cart/change.js', {
        method: 'POST',
        headers: {
          'Accept': 'application/json',
          'Content-Type': 'application/json'
        },
        body: JSON.stringify({
          line,
quantity,
sections,
sections_url }) }) .then(async (res) => {
if (res.status === 422) {
var body = await res.json();
console.log('Body', body);
return res.json()
}
return res.text()
}) .then((json) => { console.log(json); }) .catch((error) => { console.error('Error:', error); });

The code is just some sample. The errors I receive in my terminal. Is match with the errors in our Checkout Rule

JohnSmith6_0-1718014080115.png


However we actually receive something totally different when parse the body.

JohnSmith6_1-1718014352416.png

Is this intended or anyway we can get something like error response in /cart/add.js which work perfectly fine with Checkout Validation Rule

 

 

 

 

 {
"status": 422,
"message": "Cart Error",
"description": "You can't add purchase than 1 pre-order product in your cart."
}

 

 

 

 

 

Reply 1 (1)

Zainalidst
Shopify Partner
2 0 0

I am also looking the solution for this issue. 

 

Shopify added the validation on storefront api that response is mostly 422 in case of fail that is big issue and stop the execution of theme after ajax request. Can any one helpe to know who dawn theme handle the cart drawer after add and change the cart item. 

 

Thanks

Zain