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
However we actually receive something totally different when parse the body.
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."
}

