Files
supabase/apps/studio/data/integrations/github-branches-query.ts
Joshen Lim 163263c3c5 First round of wrapping RQ errors with handleError (#26384)
* 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>
2024-05-17 16:30:55 +08:00

43 lines
1.3 KiB
TypeScript

import { useQuery, UseQueryOptions } from '@tanstack/react-query'
import { get, handleError } from 'data/fetchers'
import type { ResponseError } from 'types'
import { integrationKeys } from './keys'
export type GitHubBranchesVariables = {
connectionId?: number
}
export async function getGitHubBranches(
{ connectionId }: GitHubBranchesVariables,
signal?: AbortSignal
) {
if (!connectionId) throw new Error('connectionId is required')
const { data, error } = await get(`/platform/integrations/github/branches/{connectionId}`, {
params: { path: { connectionId } },
signal,
})
if (error) handleError(error)
return data
}
export type GitHubBranchesData = Awaited<ReturnType<typeof getGitHubBranches>>
export type GitHubBranchesError = ResponseError
export const useGitHubBranchesQuery = <TData = GitHubBranchesData>(
{ connectionId }: GitHubBranchesVariables,
{
enabled = true,
...options
}: UseQueryOptions<GitHubBranchesData, GitHubBranchesError, TData> = {}
) =>
useQuery<GitHubBranchesData, GitHubBranchesError, TData>(
integrationKeys.githubBranchesList(connectionId),
({ signal }) => getGitHubBranches({ connectionId }, signal),
{
enabled: enabled && typeof connectionId !== 'undefined',
...options,
}
)