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

Commit 4305620

Browse files
authored
Merge pull request #1340 from 5n00p4eg/error-handler
Include error message into HttpRequestError
2 parents a2a3fd1 + 16f52ee commit 4305620

File tree

4 files changed

+19
-14
lines changed

4 files changed

+19
-14
lines changed

.changeset/friendly-beers-melt.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@shopify/shopify-api": patch
3+
---
4+
5+
Include error message into HttpRequestError

packages/shopify-api/lib/clients/admin/__tests__/admin_graphql_client.test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -276,18 +276,19 @@ describe('GraphQL client', () => {
276276
}
277277
}`;
278278

279-
queueError(
280-
new FetchError(
281-
`uri requested responds with an invalid redirect URL: http://test.com`,
282-
'invalid-redirect',
283-
),
279+
const fetchError = new FetchError(
280+
`uri requested responds with an invalid redirect URL: http://test.com`,
281+
'invalid-redirect',
284282
);
283+
queueError(fetchError);
284+
queueError(fetchError);
285285

286286
const request = async () => {
287287
await client.request(query);
288288
};
289289

290290
await expect(request).rejects.toThrow(HttpRequestError);
291+
await expect(request).rejects.toThrow('invalid redirect');
291292
});
292293

293294
it('allows overriding the API version', async () => {

packages/shopify-api/lib/clients/common.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,9 @@ export function throwFailedRequest(
6262
response?: Response,
6363
): never {
6464
if (typeof response === 'undefined') {
65+
const message = body?.errors?.message ?? '';
6566
throw new ShopifyErrors.HttpRequestError(
66-
'Http request error, no response available',
67-
{
68-
body,
69-
},
67+
`Http request error, no response available: ${message}`,
7068
);
7169
}
7270

packages/shopify-api/lib/clients/storefront/__tests__/storefront_client.test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,17 +181,18 @@ describe('Storefront GraphQL client', () => {
181181
apiVersion: '2020-01' as any as ApiVersion,
182182
});
183183

184-
queueError(
185-
new FetchError(
186-
`uri requested responds with an invalid redirect URL: http://test.com`,
187-
'invalid-redirect',
188-
),
184+
const fetchError = new FetchError(
185+
`uri requested responds with an invalid redirect URL: http://test.com`,
186+
'invalid-redirect',
189187
);
188+
queueError(fetchError);
189+
queueError(fetchError);
190190

191191
const request = async () => {
192192
await client.request(QUERY);
193193
};
194194

195195
await expect(request).rejects.toThrow(HttpRequestError);
196+
await expect(request).rejects.toThrow('invalid redirect');
196197
});
197198
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy