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

Commit

Permalink
Include error message into HttpRequestError
Browse files Browse the repository at this point in the history
  • Loading branch information
5n00p4eg committed Apr 9, 2024
1 parent a2a3fd1 commit a4c84d0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
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');
});
});

0 comments on commit a4c84d0

Please sign in to comment.