shopify-api-js icon indicating copy to clipboard operation
shopify-api-js copied to clipboard

RestClient.delete throw `ShopifyErrors.HttpRequestError` with status 200

Open kazukinagata opened this issue 3 years ago • 2 comments

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.

kazukinagata avatar Feb 22 '22 08:02 kazukinagata

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

RavenHursT avatar May 12 '22 05:05 RavenHursT

@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?

aditodkar avatar Aug 12 '22 11:08 aditodkar

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.

github-actions[bot] avatar Oct 12 '22 02:10 github-actions[bot]

not stale

mariusa avatar Oct 12 '22 08:10 mariusa

@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.

cquemin avatar Jan 12 '23 17:01 cquemin

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.

mkevinosullivan avatar Jan 31 '23 20:01 mkevinosullivan