A space to discuss online store customization, theme development, and Liquid templating.
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:
However, when calling GraphQL "cart update" mutations (cartLinesAdd, cartLinesUpdate), the GraphQL endpoint returns a failure INTERNAL_SERVER_ERROR message.
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.
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
}
{
"cartId": "gid://shopify/Cart/c1-70eTHECARTIDISHERE",
"lines": [
{
"merchandiseId": "gid://shopify/ProductVariant/SOMEVARIANTID",
"quantity": 1
}
]
}
{
"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"
}
}
]
}
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.
Adding a screencast video of invoking the API and demonstrating failure/success based on inclusion/omission of the code.
https://app.screencast.com/zylV87NpLGwLG