Skip to content

Commit 7b66b6a

Browse files
committed
Include result if parsed from server error
1 parent 19e8c1a commit 7b66b6a

2 files changed

Lines changed: 26 additions & 12 deletions

File tree

src/link/persisted-queries/__tests__/persisted-queries.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,9 @@ test("calls `disable` with GraphQL errors when parsed from non-2xx response", as
11481148
persistedQueryNotFound: false,
11491149
persistedQueryNotSupported: false,
11501150
},
1151+
result: {
1152+
errors: [{ message: "Something went wrong" }],
1153+
},
11511154
});
11521155
});
11531156

@@ -1496,5 +1499,8 @@ test("calls `retry` with GraphQL errors when parsed from non-2xx response", asyn
14961499
persistedQueryNotFound: false,
14971500
persistedQueryNotSupported: false,
14981501
},
1502+
result: {
1503+
errors: [{ message: "Something went wrong" }],
1504+
},
14991505
});
15001506
});

src/link/persisted-queries/index.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -248,31 +248,39 @@ export const createPersistedQueryLink = (
248248
},
249249
error: (incomingError) => {
250250
const error = toErrorLike(incomingError);
251-
let graphQLErrors: ReadonlyArray<GraphQLFormattedError> | undefined;
251+
const callback = () => observer.error(incomingError);
252252

253253
// This is persisted-query specific (see #9410) and deviates from the
254254
// GraphQL-over-HTTP spec for application/json responses.
255255
// This is intentional.
256256
if (ServerError.is(error) && error.bodyText) {
257257
try {
258-
const result = JSON.parse(error.bodyText) as
259-
| FormattedExecutionResult
260-
| undefined;
261-
262-
graphQLErrors = result?.errors;
258+
const result = JSON.parse(error.bodyText);
259+
260+
if (isFormattedExecutionResult(result)) {
261+
return handleRetry(
262+
{
263+
error: new CombinedGraphQLErrors(result),
264+
result,
265+
operation,
266+
meta: processErrors(result.errors),
267+
},
268+
callback
269+
);
270+
}
263271
} catch {}
264272
}
265273

266274
handleRetry(
267275
{
268-
error:
269-
isNonEmptyArray(graphQLErrors) ?
270-
new CombinedGraphQLErrors({ errors: graphQLErrors })
271-
: error,
276+
error,
272277
operation,
273-
meta: processErrors(graphQLErrors),
278+
meta: {
279+
persistedQueryNotSupported: false,
280+
persistedQueryNotFound: false,
281+
},
274282
},
275-
() => observer.error(incomingError)
283+
callback
276284
);
277285
},
278286
complete: observer.complete.bind(observer),

0 commit comments

Comments
 (0)