mirror of
https://github.com/supabase/supabase.git
synced 2026-07-05 01:14:23 +08: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>
38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
import { useQuery, UseQueryOptions } from '@tanstack/react-query'
|
|
|
|
import type { components } from 'data/api'
|
|
import { get, handleError } from 'data/fetchers'
|
|
import type { ResponseError } from 'types'
|
|
import { databaseKeys } from './keys'
|
|
|
|
export type BackupsVariables = {
|
|
projectRef?: string
|
|
}
|
|
|
|
export type DatabaseBackup = components['schemas']['Backup']
|
|
|
|
export async function getBackups({ projectRef }: BackupsVariables, signal?: AbortSignal) {
|
|
if (!projectRef) throw new Error('Project ref is required')
|
|
|
|
const { data, error } = await get(`/platform/database/{ref}/backups`, {
|
|
params: { path: { ref: projectRef } },
|
|
signal,
|
|
})
|
|
|
|
if (error) handleError(error)
|
|
return data
|
|
}
|
|
|
|
export type BackupsData = Awaited<ReturnType<typeof getBackups>>
|
|
export type BackupsError = ResponseError
|
|
|
|
export const useBackupsQuery = <TData = BackupsData>(
|
|
{ projectRef }: BackupsVariables,
|
|
{ enabled = true, ...options }: UseQueryOptions<BackupsData, BackupsError, TData> = {}
|
|
) =>
|
|
useQuery<BackupsData, BackupsError, TData>(
|
|
databaseKeys.backups(projectRef),
|
|
({ signal }) => getBackups({ projectRef }, signal),
|
|
{ enabled: enabled && typeof projectRef !== 'undefined', ...options }
|
|
)
|