Skip to content

Commit

Permalink
fix: handle garmr retry exclusion
Browse files Browse the repository at this point in the history
  • Loading branch information
rebelchris committed Sep 3, 2024
1 parent 9b48b75 commit f1cc227
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/shared/src/graphql/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export interface ApiErrorResult {
response: ApiResponse;
}

export const GARMR_ERROR = 'GARMR_BROKEN_ERROR';
export const DEFAULT_ERROR = 'An error occurred, please try again';

export const errorMessage = {
Expand Down
15 changes: 14 additions & 1 deletion packages/shared/src/hooks/useFeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
UseInfiniteQueryOptions,
useQueryClient,
} from '@tanstack/react-query';
import { ClientError } from 'graphql-request';
import {
Ad,
FeedData,
Expand All @@ -22,7 +23,7 @@ import {
} from '../lib/query';
import { MarketingCta } from '../components/marketingCta/common';
import { FeedItemType } from '../components/cards/common';
import { gqlClient } from '../graphql/common';
import { GARMR_ERROR, gqlClient } from '../graphql/common';

interface FeedItemBase<T extends FeedItemType> {
type: T;
Expand Down Expand Up @@ -123,8 +124,11 @@ export default function useFeed<T>(
first: pageSize,
after: pageParam,
loggedIn: !!user,
test: 'test',
});

console.log('done loading???');

if (
!feedQuery?.data?.pages[0]?.page.edges.length &&
!res?.page?.edges?.length &&
Expand All @@ -138,6 +142,15 @@ export default function useFeed<T>(
{
refetchOnMount: false,
...options,
retry: (failureCount, error) => {
const clientError = error as ClientError;
if (
clientError?.response?.errors?.[0]?.extensions?.code === GARMR_ERROR
) {
return false;
}
return failureCount < 3;
},
enabled: query && tokenRefreshed,
refetchOnReconnect: false,
refetchOnWindowFocus: false,
Expand Down

0 comments on commit f1cc227

Please sign in to comment.