Skip to content

Commit c754a96

Browse files
committed
enhance: better error codes
1 parent 155d423 commit c754a96

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

.changeset/plenty-pianos-sleep.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@graphql-tools/executor-http': patch
3+
'@graphql-hive/gateway-runtime': patch
4+
---
5+
6+
Use more specific error codes;
7+
8+
`GATEWAY_TIMEOUT` -> Server could not get a response from upstream in time
9+
`SUBREQUEST_HTTP_ERROR` -> An error occurred while making the HTTP request to the upstream
10+
`RESPONSE_VALIDATION_FAILED` -> The response from upstream did not conform to the expected GraphQL response format

packages/executors/http/src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ export function buildHTTPExecutor(
323323
}
324324

325325
function handleError(e: any) {
326+
upstreamErrorExtensions.code = 'SUBREQUEST_HTTP_ERROR';
326327
if (e.name === 'AggregateError') {
327328
return {
328329
errors: e.errors.map((e: any) =>
@@ -426,6 +427,8 @@ export function buildHTTPExecutor(
426427
parsedResult.errors.length === 0)
427428
) {
428429
const message = `Unexpected empty "data" and "errors" fields in result: ${result}`;
430+
upstreamErrorExtensions.code =
431+
'RESPONSE_VALIDATION_FAILED';
429432
return {
430433
errors: [
431434
createGraphQLError(message, {
@@ -451,6 +454,8 @@ export function buildHTTPExecutor(
451454
}
452455
return parsedResult;
453456
} catch (e: any) {
457+
upstreamErrorExtensions.code =
458+
'RESPONSE_VALIDATION_FAILED';
454459
return {
455460
errors: [
456461
createGraphQLError(
@@ -465,6 +470,7 @@ export function buildHTTPExecutor(
465470
}
466471
} else {
467472
const message = 'No response returned';
473+
upstreamErrorExtensions.code = 'RESPONSE_VALIDATION_FAILED';
468474
return {
469475
errors: [
470476
createGraphQLError(message, {

packages/runtime/src/plugins/useUpstreamTimeout.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export function useUpstreamTimeout<TContext extends Record<string, any>>(
105105
throw createGraphQLError(e.message, {
106106
extensions: {
107107
...upstreamErrorExtensions,
108-
code: 'TIMEOUT_ERROR',
108+
code: 'GATEWAY_TIMEOUT',
109109
http: {
110110
status: 504,
111111
},

0 commit comments

Comments
 (0)