You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When interacting with Shopify's GraphQL API, sometimes the response may not have a 200 status code (e.g., 403 Forbidden). In such cases, the current implementation of shopifyFetch doesn't handle the error gracefully. Specifically, it attempts to parse the JSON response, leading to a 'Unexpected end of JSON input' error.
Current Behavior:
When a non-200 status code is returned by Shopify, the following error is thrown:
{
"cause": "unknown",
"status": 500,
"message": "Unexpected end of JSON input"
}
Expected Behavior:
The function should throw a meaningful ShopifyErrorLike object, with a relevant status code and a detailed error message.
Suggested Fix:
One approach to solve this issue could be to check the response status before attempting to parse the JSON body. If the status code is not 200, a ShopifyErrorLike object could be thrown to allow for easier debugging and error handling.
if(result.status!==200){// NOTE: The `isShopifyError` method will return false on this type, I don't know whyconsterror: ShopifyErrorLike={status: result.status,message: newError(`HTTP status ${result.status}`),cause: newError('Shopify request failed')};throwerror;}
Additional Context:
According to Shopify's GraphQL API documentation, a response may have a status code other than 200 even when using GraphQL. This makes it imperative for shopifyFetch to handle such scenarios appropriately.
"""
GraphQL HTTP status codes are different from REST API status codes. Most importantly, the GraphQL API can return a 200 OK response code in cases that would typically produce 4xx or 5xx errors in REST.
"""
The text was updated successfully, but these errors were encountered:
Issue Description:
When interacting with Shopify's GraphQL API, sometimes the response may not have a 200 status code (e.g., 403 Forbidden). In such cases, the current implementation of shopifyFetch doesn't handle the error gracefully. Specifically, it attempts to parse the JSON response, leading to a 'Unexpected end of JSON input' error.
Current Behavior:
When a non-200 status code is returned by Shopify, the following error is thrown:
Expected Behavior:
The function should throw a meaningful ShopifyErrorLike object, with a relevant status code and a detailed error message.
Suggested Fix:
One approach to solve this issue could be to check the response status before attempting to parse the JSON body. If the status code is not 200, a ShopifyErrorLike object could be thrown to allow for easier debugging and error handling.
Additional Context:
According to Shopify's GraphQL API documentation, a response may have a status code other than 200 even when using GraphQL. This makes it imperative for shopifyFetch to handle such scenarios appropriately.
"""
GraphQL HTTP status codes are different from REST API status codes. Most importantly, the GraphQL API can return a 200 OK response code in cases that would typically produce 4xx or 5xx errors in REST.
"""
The text was updated successfully, but these errors were encountered: