mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 08:29:01 +00:00
## What
Moves the `ResponseError` class (`types/base.ts`) and the classified
error classes (`types/api-errors.ts`) into
`lib/errors/studio-errors.ts`, and renames `ResponseError` to
`StudioError`.
## Why
Studio's error classification is being expanded to cover errors that
don't come from API responses (thrown network failures, aborted
requests, unexpected client errors). The API-specific name and location
no longer fit. Landing the rename on its own keeps the follow-up PR,
which introduces the classified error model, small and reviewable.
## Notes for reviewers
- Mechanical change, no behavior change. Most of the diff is a one-line
import change per file plus import re-sorting by Prettier.
- Files that only use the type now use `import type { StudioError }`.
- `ResponseError` is no longer re-exported from `@/types`; there are no
compatibility shims at the old paths.
- Unrelated identifiers like `QueryResponseError` and
`parseResponseErrors` are unchanged.
65 lines
1.8 KiB
TypeScript
65 lines
1.8 KiB
TypeScript
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
|
import { toast } from 'sonner'
|
|
|
|
import { invoicesKeys } from './keys'
|
|
import { get, handleError } from '@/data/fetchers'
|
|
import type { StudioError } from '@/lib/errors/studio-errors'
|
|
import type { UseCustomMutationOptions } from '@/types'
|
|
|
|
export type InvoicePaymentLinkGetVariables = {
|
|
slug?: string
|
|
invoiceId?: string
|
|
}
|
|
|
|
export async function updateInvoicePaymentLink({
|
|
slug,
|
|
invoiceId,
|
|
}: InvoicePaymentLinkGetVariables) {
|
|
if (!slug) throw new Error('Org slug is required')
|
|
if (!invoiceId) throw new Error('Invoice ID is required')
|
|
|
|
const { data, error } = await get(
|
|
'/platform/organizations/{slug}/billing/invoices/{invoice_id}/payment-link',
|
|
{
|
|
params: {
|
|
path: {
|
|
slug,
|
|
invoice_id: invoiceId,
|
|
},
|
|
},
|
|
}
|
|
)
|
|
|
|
if (error) handleError(error)
|
|
return data
|
|
}
|
|
|
|
type InvoicePaymentLinkGetData = Awaited<ReturnType<typeof updateInvoicePaymentLink>>
|
|
|
|
export const useInvoicePaymentLinkGetMutation = ({
|
|
onError,
|
|
...options
|
|
}: Omit<
|
|
UseCustomMutationOptions<InvoicePaymentLinkGetData, StudioError, InvoicePaymentLinkGetVariables>,
|
|
'mutationFn'
|
|
> = {}) => {
|
|
const queryClient = useQueryClient()
|
|
|
|
return useMutation<InvoicePaymentLinkGetData, StudioError, InvoicePaymentLinkGetVariables>({
|
|
mutationFn: (vars) => updateInvoicePaymentLink(vars),
|
|
async onError(error, variables, context) {
|
|
// In case of an error, there is a good chance that the invoice status has changed, so we invalidate the cache to reflect the updated status
|
|
await Promise.all([
|
|
queryClient.invalidateQueries({ queryKey: invoicesKeys.listAndCount(variables.slug) }),
|
|
])
|
|
|
|
if (onError === undefined) {
|
|
toast.error(error.message)
|
|
} else {
|
|
onError(error, variables, context)
|
|
}
|
|
},
|
|
...options,
|
|
})
|
|
}
|