Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Include error message into HttpRequestError #1340

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/friendly-beers-melt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@shopify/shopify-api": patch
---

Include error message into HttpRequestError
Original file line number Diff line number Diff line change
Expand Up @@ -276,18 +276,19 @@ describe('GraphQL client', () => {
}
}`;

queueError(
new FetchError(
`uri requested responds with an invalid redirect URL: http://test.com`,
'invalid-redirect',
),
const fetchError = new FetchError(
`uri requested responds with an invalid redirect URL: http://test.com`,
'invalid-redirect',
);
queueError(fetchError);
queueError(fetchError);

const request = async () => {
await client.request(query);
};

await expect(request).rejects.toThrow(HttpRequestError);
await expect(request).rejects.toThrow('invalid redirect');
});

it('allows overriding the API version', async () => {
Expand Down
6 changes: 2 additions & 4 deletions packages/shopify-api/lib/clients/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,9 @@ export function throwFailedRequest(
response?: Response,
): never {
if (typeof response === 'undefined') {
const message = body?.errors?.message ?? '';
throw new ShopifyErrors.HttpRequestError(
'Http request error, no response available',
{
body,
},
`Http request error, no response available: ${message}`,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,17 +181,18 @@ describe('Storefront GraphQL client', () => {
apiVersion: '2020-01' as any as ApiVersion,
});

queueError(
new FetchError(
`uri requested responds with an invalid redirect URL: http://test.com`,
'invalid-redirect',
),
const fetchError = new FetchError(
`uri requested responds with an invalid redirect URL: http://test.com`,
'invalid-redirect',
);
queueError(fetchError);
queueError(fetchError);

const request = async () => {
await client.request(QUERY);
};

await expect(request).rejects.toThrow(HttpRequestError);
await expect(request).rejects.toThrow('invalid redirect');
});
});
Loading