mirror of
https://github.com/supabase/supabase.git
synced 2026-05-26 05:33:47 +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>
48 lines
1.4 KiB
TypeScript
48 lines
1.4 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 GitHubConnectionsVariables = {
|
|
organizationId?: number
|
|
}
|
|
|
|
export async function getGitHubConnections(
|
|
{ organizationId }: GitHubConnectionsVariables,
|
|
signal?: AbortSignal
|
|
) {
|
|
if (!organizationId) throw new Error('organizationId is required')
|
|
|
|
const { data, error } = await get('/platform/integrations/github/connections', {
|
|
params: {
|
|
query: {
|
|
organization_id: organizationId,
|
|
},
|
|
},
|
|
signal,
|
|
})
|
|
|
|
if (error) handleError(error)
|
|
return data.connections
|
|
}
|
|
|
|
export type GitHubConnectionsData = Awaited<ReturnType<typeof getGitHubConnections>>
|
|
export type GitHubConnectionsError = ResponseError
|
|
|
|
export type GitHubConnection = GitHubConnectionsData[0]
|
|
|
|
export const useGitHubConnectionsQuery = <TData = GitHubConnectionsData>(
|
|
{ organizationId }: GitHubConnectionsVariables,
|
|
{
|
|
enabled = true,
|
|
...options
|
|
}: UseQueryOptions<GitHubConnectionsData, GitHubConnectionsError, TData> = {}
|
|
) => {
|
|
return useQuery<GitHubConnectionsData, GitHubConnectionsError, TData>(
|
|
integrationKeys.githubConnectionsList(organizationId),
|
|
({ signal }) => getGitHubConnections({ organizationId }, signal),
|
|
{ enabled: enabled && typeof organizationId !== 'undefined', ...options }
|
|
)
|
|
}
|