Files
supabase/apps/studio/data/integrations/github-repositories-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

33 lines
1.1 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 async function getGitHubRepositories(signal?: AbortSignal) {
const { data, error } = await get('/platform/integrations/github/repositories', {
signal,
})
if (error) handleError(error)
// [Alaister]: temp fix until we have a proper response type
return (data as any).repositories
}
export type GitHubRepositoriesData = Awaited<ReturnType<typeof getGitHubRepositories>>
export type ProjectGitHubRepositoryConnectionsData = Awaited<
ReturnType<typeof getGitHubRepositories>
>
export type GitHubRepositoriesError = ResponseError
export const useGitHubRepositoriesQuery = <TData = GitHubRepositoriesData>({
enabled = true,
...options
}: UseQueryOptions<GitHubRepositoriesData, GitHubRepositoriesError, TData> = {}) => {
return useQuery<GitHubRepositoriesData, GitHubRepositoriesError, TData>(
integrationKeys.githubRepositoriesList(),
({ signal }) => getGitHubRepositories(signal),
{ enabled, staleTime: 0, ...options }
)
}