mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 08:29:01 +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.
75 lines
2.4 KiB
TypeScript
75 lines
2.4 KiB
TypeScript
import { keepPreviousData, useQuery, UseQueryResult } from '@tanstack/react-query'
|
|
|
|
import { organizationKeys } from './keys'
|
|
import type { CustomerAddress, CustomerTaxId } from './types'
|
|
import { handleError, post } from '@/data/fetchers'
|
|
import type { SubscriptionTier } from '@/data/subscriptions/types'
|
|
import type { StudioError } from '@/lib/errors/studio-errors'
|
|
import type { UseCustomQueryOptions } from '@/types'
|
|
|
|
export type OrganizationBillingSubscriptionPreviewVariables = {
|
|
organizationSlug?: string
|
|
tier?: SubscriptionTier
|
|
address?: CustomerAddress
|
|
taxId?: CustomerTaxId
|
|
}
|
|
|
|
export async function previewOrganizationBillingSubscription({
|
|
organizationSlug,
|
|
tier,
|
|
address,
|
|
taxId,
|
|
}: OrganizationBillingSubscriptionPreviewVariables) {
|
|
if (!organizationSlug) throw new Error('organizationSlug is required')
|
|
if (!tier) throw new Error('tier is required')
|
|
|
|
const { data, error } = await post(
|
|
`/platform/organizations/{slug}/billing/subscription/preview`,
|
|
{
|
|
params: { path: { slug: organizationSlug } },
|
|
body: {
|
|
tier,
|
|
...(address && { address }),
|
|
...(taxId && { tax_id: taxId }),
|
|
},
|
|
headers: {
|
|
Version: '2',
|
|
},
|
|
}
|
|
)
|
|
|
|
if (error) handleError(error)
|
|
|
|
return data
|
|
}
|
|
|
|
export type OrganizationBillingSubscriptionPreviewData = Awaited<
|
|
ReturnType<typeof previewOrganizationBillingSubscription>
|
|
>
|
|
|
|
export type OrganizationBillingSubscriptionPreviewQueryResult = UseQueryResult<
|
|
OrganizationBillingSubscriptionPreviewData,
|
|
StudioError
|
|
>
|
|
|
|
export const useOrganizationBillingSubscriptionPreview = <
|
|
TData = OrganizationBillingSubscriptionPreviewData,
|
|
>(
|
|
{ organizationSlug, tier, address, taxId }: OrganizationBillingSubscriptionPreviewVariables,
|
|
{
|
|
enabled = true,
|
|
...options
|
|
}: UseCustomQueryOptions<OrganizationBillingSubscriptionPreviewData, StudioError, TData> = {}
|
|
) =>
|
|
useQuery<OrganizationBillingSubscriptionPreviewData, StudioError, TData>({
|
|
queryKey: organizationKeys.subscriptionPreview(organizationSlug, tier, {
|
|
address: address as Record<string, unknown> | undefined,
|
|
taxId: taxId as Record<string, unknown> | undefined,
|
|
}),
|
|
queryFn: () =>
|
|
previewOrganizationBillingSubscription({ organizationSlug, tier, address, taxId }),
|
|
enabled: enabled && typeof organizationSlug !== 'undefined' && typeof tier !== 'undefined',
|
|
placeholderData: keepPreviousData,
|
|
...options,
|
|
})
|