mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 01:15:03 +03:00
Resolves FUNC-941 ## What When a project isn't enrolled in Compute, show a short notice with a link to the waitlist (https://supabase.com/compute) instead of a generic error. ## Why The compute API returns its 404 as `{ "error": { "code", "message" } }`. `handleError` only reads a top-level `message`, so it dropped the status code, `isComputeUnavailable` never matched, and users saw "API error happened while trying to communicate with the server." The query now checks `response.status === 404` directly. ## Testing - [ ] Project not enrolled in Compute: the waitlist notice shows - [ ] Enrolled project: the instance list loads as before
37 lines
1.4 KiB
TypeScript
37 lines
1.4 KiB
TypeScript
import { queryOptions } from '@tanstack/react-query'
|
|
|
|
import { computeRefetchInterval, parseComputeInstance } from './compute.utils'
|
|
import { computeKeys } from './keys'
|
|
import { get, handleError } from '@/data/fetchers'
|
|
import { IS_PLATFORM } from '@/lib/constants'
|
|
import { ResponseError } from '@/types'
|
|
|
|
export type ComputeVariables = { projectRef?: string }
|
|
export type ComputeError = ResponseError
|
|
|
|
async function getComputeInstances({ projectRef }: ComputeVariables, signal?: AbortSignal) {
|
|
if (!projectRef) throw new Error('projectRef is required')
|
|
|
|
const { data, error, response } = await get('/v2/projects/{ref}/compute', {
|
|
params: { path: { ref: projectRef } },
|
|
signal,
|
|
})
|
|
|
|
if (response.status === 404) {
|
|
throw new ResponseError('Compute is not available for this project', 404)
|
|
}
|
|
if (error) return handleError(error)
|
|
return data.data.map((instance) => parseComputeInstance(instance))
|
|
}
|
|
|
|
export type ComputeData = Awaited<ReturnType<typeof getComputeInstances>>
|
|
|
|
export const computeQueryOptions = ({ projectRef }: ComputeVariables) =>
|
|
queryOptions({
|
|
queryKey: computeKeys.list(projectRef),
|
|
queryFn: ({ signal }) => getComputeInstances({ projectRef }, signal),
|
|
enabled: IS_PLATFORM && typeof projectRef !== 'undefined',
|
|
refetchOnWindowFocus: 'always',
|
|
refetchInterval: (query) => computeRefetchInterval(query.state.data),
|
|
})
|