shopify-api-js
shopify-api-js copied to clipboard
Storefront client not showing exact error instead showing invalid json
Issue summary
I tried running storefront client to fetch products from my store. I intentionally put wrong storefront token to check the error message. Apparently I got invalid json input error. Here's the snippet code I am running ( example code provided in documentation ).
const client = new Shopify.Clients.Storefront(
shopifyShopName,
storefrontToken,
)
try {
const products = await client.query({
data: {
query: `query GetProducts($first: Int!, $query: String!) {
products (first: $first, query: $query) {
edges {
node {
id
title
descriptionHtml
}
}
}
}`,
variables: {
first: 1,
query: 'a',
},
},
})
return products.body
} catch (error) {
console.log({ error })
throw new Error(error.message)
}
Expected behavior
Error should be provided by shopify api. In this particular case it should something like token is not valid.
Actual behavior
I was given error about invalid json response body.
error: HttpRequestError: Failed to make Shopify HTTP request: FetchError: invalid json response body at https://{my-shop-name}/api/unstable/graphql.json reason: Unex
pected end of JSON input
at HttpRequestError.ShopifyError [as constructor] ({directory}/@shopify/shopify-api/dist/error.js:13:28)
at new HttpRequestError ({directory}/@shopify/shopify-api/dist/error.js:79:42)
at {directory}/@shopify/shopify-api/dist/clients/http_client/http_client.js:242:35
at processTicksAndRejections (node:internal/process/task_queues:96:5)
}
Steps to reproduce the problem
- Create new storefront client.
- Try any request that fails ( enter invalid token or shopname )
Checklist
- [x] I have described this issue in a way that is actionable (if possible)
Also getting this intermittently, from admin api:
Failed to make Shopify HTTP request: FetchError: invalid json response body at https://shop.myshopify.com/admin/api/2022-04/graphql.json reason: Unexpected token < in JSON at position 0
without any other detail. Would help to log the actual response, probably it has some detail about the error.
The same issue is happening in my server HttpRequestError: Failed to make Shopify HTTP request: FetchError: invalid json response body at https://wonderchefind.myshopify.com/admin/api/2022-07/graphql.json
but with using the Admin API.
Did someone found a solution for this?
This issue is stale because it has been open for 90 days with no activity. It will be closed if no further action occurs in 14 days.
The same issue is happening in my server
HttpRequestError: Failed to make Shopify HTTP request: FetchError: invalid json response body at https://wonderchefind.myshopify.com/admin/api/2022-07/graphql.json
but with using the Admin API. Did someone found a solution for this?
Hi sorry for replying this late. This issue can be fixed usually by generating new token. @oribenez
This issue is stale because it has been open for 90 days with no activity. It will be closed if no further action occurs in 14 days.
We are closing this issue because it has been inactive for a few months. This probably means that it is not reproducible or it has been fixed in a newer version. If it’s an enhancement and hasn’t been taken on since it was submitted, then it seems other issues have taken priority.
If you still encounter this issue with the latest stable version, please reopen using the issue template. You can also contribute directly by submitting a pull request– see the CONTRIBUTING.md file for guidelines
Thank you!