Liquid Ajax Cart tracks the state of every Shopify Cart Ajax API request using a JavaScript object called "Request state". These objects are passed as parameters to the callback functions you define when using Cart Ajax API requests functions.
Object Structure
A typical successful request state object contains:
endpoint: The URL of the request (e.g., /cart/add.js).requestBody: The payload sent. It is a JSON or FormData object for POST requests, and undefined for GET requests.requestType: The type of operation (e.g., add).info: Additional metadata provided by the caller.- When using Product forms or Controls, this includes an
initiator property containing the HTMLElement that triggered the request. - If
info.cancel is set to true, the request is aborted and responseData will not be present.
responseData: The result of the request. The ok property is true if the HTTP status is in the 200-299 range.extraResponseData: Contains data from additional requests performed by Liquid Ajax Cart to ensure the UI is synchronized (see "Extra Response Data" below).
Handling Network Errors
If a request fails due to network issues (e.g., internet disconnection), the responseData property will be missing. Instead, the object will contain a fetchError property containing the error message and stack trace.
{
"endpoint": "/cart/add.js",
"requestBody": {"items": [{"id": 40934235668668, "quantity": 1}], "sections": "my-cart"},
"requestType": "add",
"info": {
"initiator": Element {}
},
"responseData": {
"ok": true,
"status": 200,
"body": {...}
},
"extraResponseData": {
"ok": true,
"status": 200,
"body": {...}
}
}