mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 01:45:10 +03:00
* First round of wrapping RQ errors with handleError * Remove the throw before the handleError usage. * Make the handling of an API error more versatile. Add logging in Sentry if the error is of unknown type. * Remove throwing of the handleError function. * Add return type to the handleError function to be never so that we're sure it always throws. --------- Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
import { useQuery, UseQueryOptions } from '@tanstack/react-query'
|
|
|
|
import { IS_PLATFORM } from 'common'
|
|
import type { components } from 'data/api'
|
|
import { get, handleError } from 'data/fetchers'
|
|
import type { ResponseError } from 'types'
|
|
import { usageKeys } from './keys'
|
|
|
|
export async function getResourceWarnings(signal?: AbortSignal) {
|
|
const { data, error } = await get(`/platform/projects-resource-warnings`, { signal })
|
|
if (error) handleError(error)
|
|
|
|
return data
|
|
}
|
|
|
|
export type ResourceWarning = components['schemas']['ProjectResourceWarningsResponse']
|
|
export type ResourceWarningsData = Awaited<ReturnType<typeof getResourceWarnings>>
|
|
export type ResourceWarningsError = ResponseError
|
|
|
|
export const useResourceWarningsQuery = <TData = ResourceWarningsData>({
|
|
enabled = true,
|
|
...options
|
|
}: UseQueryOptions<ResourceWarningsData, ResourceWarningsError, TData> = {}) =>
|
|
useQuery<ResourceWarningsData, ResourceWarningsError, TData>(
|
|
usageKeys.resourceWarnings(),
|
|
({ signal }) => getResourceWarnings(signal),
|
|
{
|
|
enabled: IS_PLATFORM && enabled,
|
|
staleTime: 1000 * 60 * 30, // default 30 minutes
|
|
...options,
|
|
}
|
|
)
|