Skip to content

Commit

Permalink
Catch storefront api error when no valid body exists (#1205)
Browse files Browse the repository at this point in the history
* Catch error

* update message
  • Loading branch information
wizardlyhel authored Aug 8, 2023
1 parent ed0c7e0 commit b29c85d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/long-goats-poke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/hydrogen': patch
---

Surface storefront api response errors
11 changes: 10 additions & 1 deletion packages/hydrogen/src/cache/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,16 @@ export async function fetchWithServerCache(
try {
data = await response[returnType]();
} catch {
data = await response.text();
try {
data = await response.text();
} catch {
// Getting a response without a valid body
throw new Error(
`Storefront API response code: ${
response.status
} (Request Id: ${response.headers.get('x-request-id')})`,
);
}
}

return toSerializableResponse(data, response);
Expand Down

0 comments on commit b29c85d

Please sign in to comment.