INTERNAL_SERVER_ERROR calling cartLinesAdd when Checkout Validation Function Prevents It

INTERNAL_SERVER_ERROR calling cartLinesAdd when Checkout Validation Function Prevents It

mikeismyname
Shopify Partner
3 0 0

Overview

I have simple server-side validation function that raises an error if subtotal>$1000 that mimics the official published example here via docs. It's triggered when items are added or updated in the cart. It works as expected inside a liquid-driven storefront cart (via the Cart Ajax API) and raises the error message inside of checkout too with no problems as shown here:

mikeismyname_0-1702314137813.png

 

However, when calling GraphQL "cart update" mutations (cartLinesAdd, cartLinesUpdate), the GraphQL endpoint returns a failure INTERNAL_SERVER_ERROR message.

 

mikeismyname_1-1702314947777.png

 

Thoughts

  1. The checkout validation function certainly is the reason behind the failure. If the cart doesn't meet the conditions for "validation failure", then the GraphQL calls succeed with no issue.
  2. Using the graphiql util or another GraphQL client like Postman or Insomnia work fine (cart items are added/updated) until the "validation failure" threshold is met.
  3. Attempting this in context of a React/Remix Hydrogen storefront which uses GraphQL to manipulate the cart.

Expectations

Expecting something other than an INTERNAL_SERVER_ERROR. Perhaps this is normal? Regardless, it's impossible to trap and handle properly since the error payload isn't returned. Instead its the unhelpful INTERNAL_SERVER_ERROR.

GraphQL Query

 

 

mutation cartLinesAdd($cartId: ID!, $lines: [CartLineInput!]!, $country: CountryCode = GB, $language: LanguageCode = EN) @inContext(country: $country, language: $language) {
  cartLinesAdd(cartId: $cartId, lines: $lines) {
    cart {
      ...CartApiMutation
    }
    errors: userErrors {
      ...CartApiError
    }
  }
}

fragment CartApiMutation on Cart {
  id
  totalQuantity
}

fragment CartApiError on CartUserError {
  message
  field
  code
}

 

 

Variables

 

 

{
	"cartId": "gid://shopify/Cart/c1-70eTHECARTIDISHERE",
	"lines": [
		{
			"merchandiseId": "gid://shopify/ProductVariant/SOMEVARIANTID",
			"quantity": 1
		}
	]
}

 

 

Error Output

 

 

{
  "errors": [
    {
      "message": "Internal error. Looks like something went wrong on our end.\nRequest ID: f33e7361-0f30-46d6-84d7-b5cf30392c2b (include this in support requests).",
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "requestId": "f33e7361-0f30-46d6-84d7-b5cf30392c2b"
      }
    }
  ]
}

 

 

Validation Function

mikeismyname_2-1702315568720.png

 

Replies 2 (2)

mikeismyname
Shopify Partner
3 0 0

Hmm, omitting code from the CartApiError fragment seems to avoid the INTERNAL_SERVER_ERROR.

 

 

 

fragment CartApiError on CartUserError {
  message
  field
}

 

 

Seems like a Shopify platform bug.

 

Attempts to adjust the validation function's return payload to include a code, or statusCode, or something similar didn't work (this was a wild guess). Not successful in locating documentation that may let be supply the equivalent of a code.

Unfortunately, as of today, the Hydrogen reference app breaks because of the inclusion of code in the GraphQL query.

mikeismyname
Shopify Partner
3 0 0

Adding a screencast video of invoking the API and demonstrating failure/success based on inclusion/omission of the code.

https://app.screencast.com/zylV87NpLGwLG