Skip to content

Commit

Permalink
Fix unnecessary requests issue
Browse files Browse the repository at this point in the history
Seems that sometimes the app can get into a request retry loop and it can cause cascading requests.

Part of the issue is that in the case of 401s a separate (from RC) handler performs it's own re-request.

This disables retrying for now until I can figure out the right mix.
  • Loading branch information
thostetler committed Feb 29, 2024
1 parent deb541e commit 07669c6
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
27 changes: 27 additions & 0 deletions global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,30 @@ declare module 'iron-session' {
bot?: boolean;
}
}

declare global {
namespace NodeJS {
interface ProcessEnv {
[key: string]: string | undefined;
BASE_CANONICAL_URL: string;
API_HOST_CLIENT: string;
API_HOST_SERVER: string;
NEXT_PUBLIC_API_HOST_CLIENT: string;
COOKIE_SECRET: string;
ADS_SESSION_COOKIE_NAME: string;
SCIX_SESSION_COOKIE_NAME: string;
NEXT_PUBLIC_ORCID_CLIENT_ID: string;
NEXT_PUBLIC_ORCID_API_URL: string;
NEXT_PUBLIC_ORCID_REDIRECT_URI: string;
REDIS_HOST: string;
REDIS_PORT: string;
REDIS_PASSWORD: string;
VERIFIED_BOTS_ACCESS_TOKEN: string;
UNVERIFIABLE_BOTS_ACCESS_TOKEN: string;
MALICIOUS_BOTS_ACCESS_TOKEN: string;
NEXT_PUBLIC_GTM_ID: string;
NEXT_PUBLIC_RECAPTCHA_SITE_KEY: string;
NEXT_PUBLIC_API_MOCKING: string;
}
}
}
5 changes: 5 additions & 0 deletions src/api/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ const resolveApiBaseUrl = (defaultBaseUrl = ''): string => {
return 'http://localhost';
}

// use a known URL for development
if (process.env.NODE_ENV === 'development' && typeof process.env.NEXT_PUBLIC_API_HOST_CLIENT === 'string') {
return process.env.NEXT_PUBLIC_API_HOST_CLIENT;
}

const config = getConfig() as AppRuntimeConfig;

if (typeof config === 'undefined') {
Expand Down
16 changes: 14 additions & 2 deletions src/lib/useCreateQueryClient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import axios from 'axios';
import { useState } from 'react';
import { QueryCache, QueryClient } from '@tanstack/react-query';
import { MutationCache, QueryCache, QueryClient } from '@tanstack/react-query';
import { logger } from '../../logger/logger';

export const useCreateQueryClient = () => {
const queryCache = new QueryCache({
Expand All @@ -11,7 +12,15 @@ export const useCreateQueryClient = () => {
}

if (axios.isAxiosError(error) || error instanceof Error) {
// TODO: global error, what should be done here?
logger.error({ msg: 'Query error', error, query });
}
},
});

const mutationCache = new MutationCache({
onError: (error, mutation) => {
if (axios.isAxiosError(error) || error instanceof Error) {
logger.error({ msg: 'Mutation error', error, mutation });
}
},
});
Expand All @@ -25,9 +34,12 @@ export const useCreateQueryClient = () => {
refetchOnMount: false,
refetchOnReconnect: false,
staleTime: Infinity,
retry: false,
retryOnMount: false,
},
},
queryCache,
mutationCache,
}),
);

Expand Down

0 comments on commit 07669c6

Please sign in to comment.