mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
## What
Moves the `ResponseError` class (`types/base.ts`) and the classified
error classes (`types/api-errors.ts`) into
`lib/errors/studio-errors.ts`, and renames `ResponseError` to
`StudioError`.
## Why
Studio's error classification is being expanded to cover errors that
don't come from API responses (thrown network failures, aborted
requests, unexpected client errors). The API-specific name and location
no longer fit. Landing the rename on its own keeps the follow-up PR,
which introduces the classified error model, small and reviewable.
## Notes for reviewers
- Mechanical change, no behavior change. Most of the diff is a one-line
import change per file plus import re-sorting by Prettier.
- Files that only use the type now use `import type { StudioError }`.
- `ResponseError` is no longer re-exported from `@/types`; there are no
compatibility shims at the old paths.
- Unrelated identifiers like `QueryResponseError` and
`parseResponseErrors` are unchanged.
57 lines
2.0 KiB
TypeScript
57 lines
2.0 KiB
TypeScript
import { useQuery } from '@tanstack/react-query'
|
|
|
|
import { platformWebhooksKeys } from './keys'
|
|
import { listWebhookDeliveries, type WebhookScopeParams } from './platform-webhooks-fetchers'
|
|
import { toWebhookDelivery } from './platform-webhooks-mappers'
|
|
import type { WebhookDelivery } from '@/components/interfaces/Platform/Webhooks/PlatformWebhooks.types'
|
|
import { getDeliveriesRefetchInterval } from '@/components/interfaces/Platform/Webhooks/PlatformWebhooksPage.utils'
|
|
import type { StudioError } from '@/lib/errors/studio-errors'
|
|
import type { UseCustomQueryOptions } from '@/types'
|
|
|
|
interface WebhookDeliveriesVariables {
|
|
scope: WebhookScopeParams
|
|
endpointId: string
|
|
size?: number
|
|
after?: string
|
|
before?: string
|
|
}
|
|
|
|
async function getWebhookDeliveries(
|
|
{ scope, endpointId, size, after, before }: WebhookDeliveriesVariables,
|
|
signal?: AbortSignal
|
|
): Promise<WebhookDelivery[]> {
|
|
const result = await listWebhookDeliveries(scope, endpointId, { size, after, before }, signal)
|
|
return (result?.data ?? []).map((delivery) => toWebhookDelivery(delivery, endpointId))
|
|
}
|
|
|
|
export type WebhookDeliveriesData = Awaited<ReturnType<typeof getWebhookDeliveries>>
|
|
|
|
export const useWebhookDeliveriesQuery = <TData = WebhookDeliveriesData>(
|
|
variables: WebhookDeliveriesVariables,
|
|
{
|
|
enabled = true,
|
|
isLive = false,
|
|
isAwaitingDelivery = false,
|
|
...options
|
|
}: UseCustomQueryOptions<WebhookDeliveriesData, StudioError, TData> & {
|
|
isLive?: boolean
|
|
isAwaitingDelivery?: boolean
|
|
} = {}
|
|
) => {
|
|
const { scope, endpointId, size, after, before } = variables
|
|
|
|
return useQuery<WebhookDeliveriesData, StudioError, TData>({
|
|
queryKey: platformWebhooksKeys.deliveries(scope, endpointId, size, after, before),
|
|
queryFn: ({ signal }) =>
|
|
getWebhookDeliveries({ scope, endpointId, size, after, before }, signal),
|
|
enabled: enabled && Boolean(endpointId),
|
|
refetchInterval: (query) =>
|
|
getDeliveriesRefetchInterval({
|
|
isLive,
|
|
isAwaitingDelivery,
|
|
deliveries: query.state.data ?? [],
|
|
}),
|
|
...options,
|
|
})
|
|
}
|