shopify-api-js
shopify-api-js copied to clipboard
RestClient.delete throw `ShopifyErrors.HttpRequestError` with status 200
Issue summary
When I make a request using RestClient.delete({path: "recurring_application_charges/{id}"}), the error is caught in the try-catch clause, even though the status code is a 200 response.
error HttpRequestError: Failed to make Shopify HTTP request: FetchError: invalid json response body at https://{shop}.myshopify.com/admin/api/2021-10/recurring_application_charges/{id}.json reason: Unexpected end of JSON input
This is because the delete endpoint is returning only the status code and executing await response.json() inside the fetch.
https://github.com/Shopify/shopify-node-api/blob/main/src/clients/http_client/http_client.ts#L184
To avoid throwing an error even if request.body is null, why don't you modify the code as follows?
const body = await response.json().catch(() => {});
Expected behavior
Status 200 without ShopifyErrors.HttpRequestError
Actual behavior
Status 200 with ShopifyErrors.HttpRequestError.
I'm seeing this as well. Sometimes it's because we're trying to fetch something for a theme that's been deleted on the given shop.
Kind've frustrating that there's no info given on the error w/r/t to the response to introspect status code or some other way to handle this gracefully
@kazukinagata @RavenHursT I am also facing same issue. I was able to upgrade recurring charge payment but for downgrade I am getting same error but on partner dashboard I see payment subscription is getting cancelled. What is temporary fix 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.
not stale
@kazukinagata we have updated the library to v6 a couple of month ago. Could you try to update to new version and let me know if this is still an issue? As you can see here we are handling the response deserialization a bit differently now and I believe you should not have the issue anymore.
The original issue was fixed in June 2022 and released as part of 3.1.2 on June 7 ... the code has been carried forward through all releases to v5.3.0.
In v6, due to the underlying isomorphic changes, the code is different but the JSON.parse is still within a try {} catch {} block to prevent the error.