mirror of
https://github.com/supabase/supabase.git
synced 2026-07-03 18:04:42 +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>
33 lines
1.1 KiB
TypeScript
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 }
|
|
)
|
|
}
|