Prevent sending requests that are known to fail
In case it's still unknown if auth is set up on the server, only the initial request to detect this should be sent. Since all other requests will also just fail, they should be blocked until the auth initialization is completed. While the access token is getting refreshed, no request will succeed since the access token is expired; thus, they should not be sent.
This commit is contained in:
@@ -29,6 +29,7 @@ import { MaybeMasked, OperationVariables, Reference } from '@apollo/client/core'
|
||||
import { useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { IRestClient, RestClient } from '@/lib/requests/client/RestClient.ts';
|
||||
import { GraphQLClient } from '@/lib/requests/client/GraphQLClient.ts';
|
||||
import { BaseClient } from '@/lib/requests/client/BaseClient.ts';
|
||||
import {
|
||||
CategoryOrderBy,
|
||||
ChapterConditionInput,
|
||||
@@ -452,6 +453,12 @@ export class RequestManager {
|
||||
|
||||
private readonly imageQueue = new Queue(5);
|
||||
|
||||
constructor() {
|
||||
BaseClient.setTokenRefreshCompleteCallback(() => {
|
||||
this.processQueues();
|
||||
});
|
||||
}
|
||||
|
||||
public getClient(): IRestClient {
|
||||
return this.restClient;
|
||||
}
|
||||
@@ -463,6 +470,7 @@ export class RequestManager {
|
||||
|
||||
public reset(): void {
|
||||
AuthManager.setAuthRequired(null);
|
||||
AuthManager.setAuthInitialized(false);
|
||||
AuthManager.removeTokens();
|
||||
this.graphQLClient.client.resetStore();
|
||||
this.graphQLClient.terminateSubscriptions();
|
||||
@@ -470,6 +478,11 @@ export class RequestManager {
|
||||
this.imageQueue.clear();
|
||||
}
|
||||
|
||||
public processQueues(): void {
|
||||
this.graphQLClient.processQueue();
|
||||
this.restClient.processQueue();
|
||||
}
|
||||
|
||||
public getBaseUrl(): string {
|
||||
return this.restClient.getBaseUrl();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user