mirror of
https://github.com/supabase/supabase.git
synced 2026-10-15 06:09:08 +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>
29 lines
987 B
TypeScript
29 lines
987 B
TypeScript
import type { Notification } from '@supabase/shared-types/out/notifications'
|
|
import { useQuery, UseQueryOptions } from '@tanstack/react-query'
|
|
|
|
import { get, handleError } from 'data/fetchers'
|
|
import type { ResponseError } from 'types'
|
|
import { notificationKeys } from './keys'
|
|
|
|
export type NotificationsResponse = Notification[]
|
|
|
|
export async function getNotificationsSummary(signal?: AbortSignal) {
|
|
const { data, error } = await get('/platform/notifications/summary', {
|
|
signal,
|
|
})
|
|
if (error) handleError(error)
|
|
return data
|
|
}
|
|
|
|
export type NotificationsData = Awaited<ReturnType<typeof getNotificationsSummary>>
|
|
export type NotificationsError = ResponseError
|
|
|
|
export const useNotificationsSummaryQuery = <TData = NotificationsData>(
|
|
options: UseQueryOptions<NotificationsData, NotificationsError, TData> = {}
|
|
) =>
|
|
useQuery<NotificationsData, NotificationsError, TData>(
|
|
notificationKeys.summary(),
|
|
({ signal }) => getNotificationsSummary(signal),
|
|
options
|
|
)
|