fix(front-end): fix issues with expired accessToken refreshment queue
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
ae466b879c
commit
d4489f691b
|
@ -9,7 +9,12 @@ let isRefreshing = false;
|
||||||
let pendingRequests: any[] = [];
|
let pendingRequests: any[] = [];
|
||||||
|
|
||||||
const resolvePendingRequests = () => {
|
const resolvePendingRequests = () => {
|
||||||
pendingRequests.map((callback) => callback());
|
console.debug("resolving pending requests");
|
||||||
|
pendingRequests.map((callback) => {
|
||||||
|
console.debug("calling callback", callback);
|
||||||
|
return callback();
|
||||||
|
});
|
||||||
|
console.debug("emptying pending requests after resolving them all");
|
||||||
pendingRequests = [];
|
pendingRequests = [];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -21,7 +26,23 @@ const isAuthError = (graphQLError: GraphQLError | undefined) => {
|
||||||
|
|
||||||
const errorLink = onError(
|
const errorLink = onError(
|
||||||
({ graphQLErrors, networkError, forward, operation }) => {
|
({ graphQLErrors, networkError, forward, operation }) => {
|
||||||
console.debug("We have an apollo error", [graphQLErrors, networkError]);
|
if (graphQLErrors) {
|
||||||
|
graphQLErrors.map(
|
||||||
|
(graphQLError: GraphQLError & { status_code?: number }) => {
|
||||||
|
if (graphQLError?.status_code !== 401) {
|
||||||
|
console.debug(
|
||||||
|
`[GraphQL error]: Message: ${graphQLError.message}, Location: ${graphQLError.locations}, Path: ${graphQLError.path}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (networkError) {
|
||||||
|
console.error(`[Network error]: ${networkError}`);
|
||||||
|
console.debug(JSON.stringify(networkError));
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
graphQLErrors?.some((graphQLError) => isAuthError(graphQLError)) ||
|
graphQLErrors?.some((graphQLError) => isAuthError(graphQLError)) ||
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
|
@ -67,6 +88,9 @@ const errorLink = onError(
|
||||||
})
|
})
|
||||||
).filter((value) => Boolean(value));
|
).filter((value) => Boolean(value));
|
||||||
} else {
|
} else {
|
||||||
|
console.debug(
|
||||||
|
"Skipping refreshing as isRefreshing is already to true, adding requests to pending"
|
||||||
|
);
|
||||||
forwardOperation = fromPromise(
|
forwardOperation = fromPromise(
|
||||||
new Promise((resolve) => {
|
new Promise((resolve) => {
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
|
@ -78,23 +102,6 @@ const errorLink = onError(
|
||||||
|
|
||||||
return forwardOperation.flatMap(() => forward(operation));
|
return forwardOperation.flatMap(() => forward(operation));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (graphQLErrors) {
|
|
||||||
graphQLErrors.map(
|
|
||||||
(graphQLError: GraphQLError & { status_code?: number }) => {
|
|
||||||
if (graphQLError?.status_code !== 401) {
|
|
||||||
console.debug(
|
|
||||||
`[GraphQL error]: Message: ${graphQLError.message}, Location: ${graphQLError.locations}, Path: ${graphQLError.path}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (networkError) {
|
|
||||||
console.error(`[Network error]: ${networkError}`);
|
|
||||||
console.debug(JSON.stringify(networkError));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ if (!import.meta.env.VITE_HISTOIRE_ENV) {
|
||||||
|
|
||||||
const retryLink = new RetryLink();
|
const retryLink = new RetryLink();
|
||||||
|
|
||||||
export const fullLink = authMiddleware
|
export const fullLink = retryLink
|
||||||
.concat(retryLink)
|
|
||||||
.concat(errorLink)
|
.concat(errorLink)
|
||||||
|
.concat(authMiddleware)
|
||||||
.concat(link ?? uploadLink);
|
.concat(link ?? uploadLink);
|
||||||
|
|
Loading…
Reference in a new issue