So I've 2 components, Token.jsx and httpRequest.jsx. Both of them call each other when the token expires and it goes into an infinite loop, I want to break the loop after 3 http erros.
export default function GenerateToken() {
  return new Promise(((resolve) => {
    const refreshToken = GetRefreshToken();
    const url = `${cloudFunctionURL}/users/auth/idtoken/refresh`;
    const headers = {
      'Content-Type': 'application/json',
    };
    const params = {
      refreshToken,
    };
    httpRequest.makeHTTPCall('post', url, headers, params).then((tokenObject) => {
      // Storing the idToken in localstorage
      // reactLocalStorage.set('PL_IdToken', tokenObject.idToken);
      StoreIdToken(`Id ${tokenObject.id_token}`);
      StoreUserId(tokenObject.user_id);
      StoreRefreshToken(tokenObject.refresh_token);
      resolve(tokenObject.id_token);
    });
  }));
}
// 2nd File
function makeHTTPCall(method, url, headers, params = null) {
  return new Promise((resolve, reject) => {
    headers.Authorization = GetIdToken();
    headers['Content-Type'] = 'application/json';
    qwest.setDefaultDataType('json');
    qwest.setDefaultOptions({
      headers,
    });
    // Make http request
    qwest[`${method}`](url, params)
      .then((xhr, response) => {
        resolve(response);
      })
      .catch((error, xhr) => {
        if (xhr.status === 401) { // IdToken expired
          GenerateToken().then(() => {
            resolve(GET(url));
          });
        }
        else {
          reject(error); // error
        }
      });
  });
}
 
    