feat: web only retry query errors on certain HTTP statuses like ky

pull/715/head
Travis Fischer 2025-06-17 16:05:49 +07:00
rodzic 28479f72a1
commit 07a1896e69
8 zmienionych plików z 81 dodań i 12 usunięć

Wyświetl plik

@ -1,11 +1,11 @@
'use client'
import { useInfiniteQuery } from '@tanstack/react-query'
import Link from 'next/link'
import useInfiniteScroll from 'react-infinite-scroll-hook'
import { useAuthenticatedAgentic } from '@/components/agentic-provider'
import { LoadingIndicator } from '@/components/loading-indicator'
import { useInfiniteQuery } from '@/lib/query-client'
export function AppIndex() {
const ctx = useAuthenticatedAgentic()

Wyświetl plik

@ -1,9 +1,8 @@
'use client'
import { useQuery } from '@tanstack/react-query'
import { useAuthenticatedAgentic } from '@/components/agentic-provider'
import { LoadingIndicator } from '@/components/loading-indicator'
import { useQuery } from '@/lib/query-client'
export function AppConsumerIndex({ consumerId }: { consumerId: string }) {
const ctx = useAuthenticatedAgentic()

Wyświetl plik

@ -1,11 +1,11 @@
'use client'
import { useInfiniteQuery } from '@tanstack/react-query'
import Link from 'next/link'
import useInfiniteScroll from 'react-infinite-scroll-hook'
import { useAuthenticatedAgentic } from '@/components/agentic-provider'
import { LoadingIndicator } from '@/components/loading-indicator'
import { useInfiniteQuery } from '@/lib/query-client'
export function AppConsumersIndex() {
const ctx = useAuthenticatedAgentic()

Wyświetl plik

@ -1,9 +1,8 @@
'use client'
import { useQuery } from '@tanstack/react-query'
import { useAuthenticatedAgentic } from '@/components/agentic-provider'
import { LoadingIndicator } from '@/components/loading-indicator'
import { useQuery } from '@/lib/query-client'
export function AppProjectIndex({
projectIdentifier

Wyświetl plik

@ -1,11 +1,11 @@
'use client'
import { useInfiniteQuery } from '@tanstack/react-query'
import Link from 'next/link'
import useInfiniteScroll from 'react-infinite-scroll-hook'
import { useAgentic } from '@/components/agentic-provider'
import { LoadingIndicator } from '@/components/loading-indicator'
import { useInfiniteQuery } from '@/lib/query-client'
export function MarketplaceIndex() {
const ctx = useAgentic()

Wyświetl plik

@ -1,7 +1,6 @@
'use client'
import { assert, omit } from '@agentic/platform-core'
import { useQuery } from '@tanstack/react-query'
import { redirect } from 'next/navigation'
import { useCallback, useEffect } from 'react'
import { useSearchParam } from 'react-use'
@ -10,6 +9,7 @@ import { useAgentic } from '@/components/agentic-provider'
import { LoadingIndicator } from '@/components/loading-indicator'
import { Button } from '@/components/ui/button'
import { toast, toastError } from '@/lib/notifications'
import { useQuery } from '@/lib/query-client'
export function MarketplaceProjectIndex({
projectIdentifier

Wyświetl plik

@ -1,3 +1,77 @@
import { QueryClient } from '@tanstack/react-query'
import {
type DefaultError,
type InfiniteData,
QueryClient,
type QueryKey,
useInfiniteQuery as useInfiniteQueryBase,
useQuery as useQueryBase
} from '@tanstack/react-query'
import { HTTPError } from 'ky'
export const queryClient = new QueryClient()
const retryStatusCodes = new Set([408, 413, 429, 500, 502, 503, 504])
function retry(failureCount: number, error: any): boolean {
if (error instanceof HTTPError) {
const { status } = error.response
if (!retryStatusCodes.has(status)) {
return false
}
}
return failureCount < 3
}
export function useQuery<
TQueryFnData = unknown,
TError = DefaultError,
TData = TQueryFnData,
TQueryKey extends QueryKey = QueryKey
>(
opts: Parameters<
typeof useQueryBase<TQueryFnData, TError, TData, TQueryKey>
>[0]
): ReturnType<typeof useQueryBase<TQueryFnData, TError, TData, TQueryKey>> {
return useQueryBase<TQueryFnData, TError, TData, TQueryKey>({
retry,
...opts
})
}
export function useInfiniteQuery<
TQueryFnData,
TError = DefaultError,
TData = InfiniteData<TQueryFnData>,
TQueryKey extends QueryKey = QueryKey,
TPageParam = unknown
>(
opts: Parameters<
typeof useInfiniteQueryBase<
TQueryFnData,
TError,
TData,
TQueryKey,
TPageParam
>
>[0]
): ReturnType<
typeof useInfiniteQueryBase<
TQueryFnData,
TError,
TData,
TQueryKey,
TPageParam
>
> {
return useInfiniteQueryBase<
TQueryFnData,
TError,
TData,
TQueryKey,
TPageParam
>({
retry,
...opts
})
}

Wyświetl plik

@ -20,9 +20,6 @@
- handle unauthenticated checkout flow => auth and then redirect to create a checkout session
- will need a `redirect` url for `/login` and `/signup`
- `/marketplace/projects/@{projectIdentifier}/checkout?plan={plan}`
- data loading / react-query
- don't retry queries on 401/403
- mimic logic from `ky` for automatic retries
- stripe
- stripe checkout
- stripe billing portal