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.
80 lines
2.3 KiB
TypeScript
80 lines
2.3 KiB
TypeScript
import { useQuery } from '@tanstack/react-query'
|
|
|
|
import { organizationKeys } from './keys'
|
|
import { get, handleError, unguarded } from '@/data/fetchers'
|
|
import type { StudioError } from '@/lib/errors/studio-errors'
|
|
import type { UseCustomQueryOptions } from '@/types'
|
|
|
|
type OrganizationProjectClaimVariables = {
|
|
slug: string
|
|
token: string
|
|
}
|
|
|
|
// todo replace with API type once exposed again - components['schemas']['OrganizationProjectClaimResponse']
|
|
export type OrganizationProjectClaimResponse = {
|
|
created_at: string
|
|
/** Format: uuid */
|
|
created_by: string
|
|
expires_at: string
|
|
preview: {
|
|
errors: {
|
|
key: string
|
|
message: string
|
|
}[]
|
|
info: {
|
|
key: string
|
|
message: string
|
|
}[]
|
|
members_exceeding_free_project_limit: {
|
|
limit: number
|
|
name: string
|
|
}[]
|
|
/** @enum {string} */
|
|
source_subscription_plan: 'free' | 'pro' | 'team' | 'enterprise'
|
|
target_organization_eligible: boolean | null
|
|
target_organization_has_free_project_slots: boolean | null
|
|
/** @enum {string|null} */
|
|
target_subscription_plan: 'free' | 'pro' | 'team' | 'enterprise' | null
|
|
valid: boolean
|
|
warnings: {
|
|
key: string
|
|
message: string
|
|
}[]
|
|
}
|
|
project: {
|
|
name: string
|
|
ref: string
|
|
}
|
|
}
|
|
|
|
async function getOrganizationProjectClaim(
|
|
{ slug, token }: OrganizationProjectClaimVariables,
|
|
signal?: AbortSignal
|
|
) {
|
|
if (!slug || !token) throw new Error('Slug and token are required')
|
|
|
|
const { data, error } = await get(`/v1/organizations/{slug}/project-claim/{token}`, {
|
|
params: { path: { slug, token } },
|
|
signal,
|
|
grant: unguarded.migrating,
|
|
})
|
|
|
|
if (error) handleError(error)
|
|
return data as OrganizationProjectClaimResponse
|
|
}
|
|
|
|
export type OrganizationProjectClaimData = Awaited<ReturnType<typeof getOrganizationProjectClaim>>
|
|
export type OrganizationProjectClaimError = StudioError
|
|
|
|
export const useOrganizationProjectClaimQuery = <TData = OrganizationProjectClaimData>(
|
|
{ slug, token }: OrganizationProjectClaimVariables,
|
|
{
|
|
...options
|
|
}: UseCustomQueryOptions<OrganizationProjectClaimData, OrganizationProjectClaimError, TData> = {}
|
|
) =>
|
|
useQuery<OrganizationProjectClaimData, OrganizationProjectClaimError, TData>({
|
|
queryKey: organizationKeys.projectClaim(slug, token),
|
|
queryFn: ({ signal }) => getOrganizationProjectClaim({ slug, token }, signal),
|
|
...options,
|
|
})
|