mirror of
https://github.com/supabase/supabase.git
synced 2026-10-10 11:55:05 +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>
51 lines
1.4 KiB
TypeScript
51 lines
1.4 KiB
TypeScript
import { useQuery, UseQueryOptions } from '@tanstack/react-query'
|
|
|
|
import { get, handleError } from 'data/fetchers'
|
|
import type { ResponseError } from 'types'
|
|
import { analyticsKeys } from './keys'
|
|
|
|
export type ProjectLogRequestsCountVariables = {
|
|
projectRef?: string
|
|
}
|
|
|
|
export async function getProjectLogRequestsCountStats(
|
|
{ projectRef }: ProjectLogRequestsCountVariables,
|
|
signal?: AbortSignal
|
|
) {
|
|
if (!projectRef) {
|
|
throw new Error('projectRef is required')
|
|
}
|
|
|
|
const { data, error } = await get(
|
|
'/platform/projects/{ref}/analytics/endpoints/usage.api-requests-count',
|
|
{
|
|
params: { path: { ref: projectRef } },
|
|
signal,
|
|
}
|
|
)
|
|
|
|
if (error) handleError(error)
|
|
return data
|
|
}
|
|
|
|
export type ProjectLogRequestsCountData = Awaited<
|
|
ReturnType<typeof getProjectLogRequestsCountStats>
|
|
>
|
|
export type ProjectLogRequestsCountError = ResponseError
|
|
|
|
export const useProjectLogRequestsCountQuery = <TData = ProjectLogRequestsCountData>(
|
|
{ projectRef }: ProjectLogRequestsCountVariables,
|
|
{
|
|
enabled = true,
|
|
...options
|
|
}: UseQueryOptions<ProjectLogRequestsCountData, ProjectLogRequestsCountError, TData> = {}
|
|
) =>
|
|
useQuery<ProjectLogRequestsCountData, ProjectLogRequestsCountError, TData>(
|
|
analyticsKeys.usageApiRequestsCount(projectRef),
|
|
({ signal }) => getProjectLogRequestsCountStats({ projectRef }, signal),
|
|
{
|
|
enabled: enabled && typeof projectRef !== 'undefined',
|
|
...options,
|
|
}
|
|
)
|