Another attempt at fixing broken retry for apollo error handling.
This commit is contained in:
@@ -5,13 +5,15 @@ import { auth } from "../firebase/firebase.utils";
|
||||
|
||||
const errorLink = onError(
|
||||
({ graphQLErrors, networkError, operation, forward }) => {
|
||||
// console.log("graphQLErrors", graphQLErrors);
|
||||
// console.log("networkError", networkError);
|
||||
// console.log("operation", operation);
|
||||
// console.log("forward", forward);
|
||||
if (graphQLErrors)
|
||||
graphQLErrors.forEach(({ message, locations, path }) =>
|
||||
console.log(
|
||||
`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`
|
||||
)
|
||||
);
|
||||
if (networkError) console.log(`[Network error]: ${networkError}`);
|
||||
|
||||
let expired = false;
|
||||
|
||||
if (graphQLErrors) {
|
||||
if (graphQLErrors[0].message.includes("JWTExpired")) {
|
||||
expired = true;
|
||||
@@ -33,12 +35,14 @@ const errorLink = onError(
|
||||
if (token) {
|
||||
console.log("Got the new token.", token);
|
||||
window.localStorage.setItem("token", token);
|
||||
operation.setContext(({ headers = {} }) => ({
|
||||
|
||||
const oldHeaders = operation.getContext().headers;
|
||||
operation.setContext({
|
||||
headers: {
|
||||
...headers,
|
||||
...oldHeaders,
|
||||
authorization: token ? `Bearer ${token}` : ""
|
||||
}
|
||||
}));
|
||||
});
|
||||
|
||||
return forward(operation);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user