Error - About Cart AJAX response in online store

Topic summary

A Shopify developer encountered a discrepancy between documented and actual Cart AJAX error responses. According to official documentation, error responses should follow a specific JSON format with status, message, and description fields. However, the current API returns responses as JavaScript object literals instead of proper JSON strings.

Impact on Dawn Theme:

  • The format change prevents error messages from displaying correctly
  • The theme’s error handling code expects standard JSON responses via response.json()
  • Code screenshots show the affected error handling logic

Proposed Solution:
Modify the Dawn theme’s onSubmitHandler to accommodate both response formats by:

  • Checking response type before processing
  • Handling both JSON and object literal formats
  • Displaying error messages when data.status and data.message exist

Status: Unclear whether this represents a Shopify API bug or intentional update. Recommendation made to check Shopify’s latest API changelog or contact support for clarification.

Summarized with AI on October 27. AI used: claude-sonnet-4-5-20250929.

Follow the docs when Cart add return error response would be like this:

but currently It’s like this

Because of this change, my Dawn theme can’t display error message. Code in Dawn theme below:

Does anyone know If this is a bug or a new update from Shopify?

1 Like

Hi @tungnk ,

Based on the provided error response documentation and the current response you’re receiving, it seems the format has changed. The documented error response includes a status, message, and description in a JSON structure, like:

{
  "status": 422,
  "message": "Cart Error",
  "description": null
}

However, your current response shows:

{status: 422, message: "Selling period has not started yet.", description: null} [Prototype]: Object

The current format appears to be a JavaScript object literal rather than a proper JSON string, which might be causing compatibility issues with your Dawn theme’s error handling code. The Dawn theme code seems to expect a JSON response (e.g., response.json()), but the current response might not be parsed correctly due to this change.

This could indicate a new update or change in Shopify’s API behavior rather than a bug. To confirm, I recommend checking the latest Shopify API documentation or changelog for updates related to cart error responses. If this is unintended, it might be a bug—consider reaching out to Shopify support with your observations.

For a quick fix in your Dawn theme, you could modify the onSubmitHandler to handle both JSON and object literal responses. Update the code to check the response type before processing:

fetch('/cart/add.js', {
  method: 'POST',
  body: JSON.stringify(formData),
  headers: { 'Content-Type': 'application/json' }
})
  .then((response) => response.json())
  .then((data) => {
    if (data.status && data.message) {
      // Handle error
      const errorMessage = data.message;
      const soldOutMessage = document.querySelector('.sold-out-message');
      if (soldOutMessage) {
        soldOutMessage.textContent = errorMessage;
        soldOutMessage.classList.remove('hidden');
      }
    } else {
      // Success case
      window.location = '/cart';
    }
  })
  .catch((error) => console.error('Error:', error));

Thanks!

1 Like

Hi @websensepro ,

Thank for your comment

As your comment, The Dawn theme has errors at the moment, right?

Hi @tungnk ,

Yes, based on the information provided, it seems the Dawn theme is encountering errors due to the change in the error response format from Shopify’s API. The theme’s current code expects a JSON response, but the new object literal format is causing compatibility issues, preventing the error message from displaying correctly. The suggested code adjustment should help resolve this issue.