Files
supabase/apps/studio/components/interfaces/Support/SupportSidebarForm.tsx
T
Jordi EnricandClaude Sonnet 4.6 42ca11f89e fix(support): handle rate-limited support submissions gracefully (#46928)
## Problem

When a support ticket submission is rejected by the API's rate limiter,
the form surfaced the raw server exception text to the user and reported
every rejection as an application error. This produced a steady stream
of noisy error reports for what is actually expected, recoverable
behavior.

The rejections are not random: the submit endpoint allows only a small
number of requests in a short window, so a quick second submission (a
fast retry or a follow-up ticket moments later) gets rejected. The first
submission usually succeeds; it's the immediate follow-up that fails.
Surfacing the raw error and logging it made this look worse than it is.

Separately, the success screen had only top padding, leaving its actions
flush against the bottom edge of the card.

## Fix

- Detect the rate-limit response and show a clear, friendly message that
tells the user how long to wait before trying again, instead of the raw
exception text.
- Stop reporting rate-limit rejections as errors to our monitoring. They
are expected and recoverable, so they no longer add noise.
- Give the success state the same vertical padding as the rest of the
form so its actions are not flush against the card edge.

## How to test

- Open the support form and simulate a 429 from the submit endpoint.
- Expected: a friendly message telling the user when they can retry, and
no error reported to monitoring.
- Submit a ticket successfully and confirm the success screen has even
padding above and below its content.

## Notes

This covers the user-facing handling. The rate-limit threshold itself is
tuned conservatively on the API and can be revisited separately so that
ordinary, legitimate resubmissions are not caught.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Bug Fixes**
* Improved support form handling for rate-limited (429) submissions by
suppressing unnecessary error reporting while still showing the error
and returning the form to editing.
* Fixed inconsistent support form spacing so padding is consistent
regardless of submission outcome.
* **Improvements**
* Propagated backend error `code` through the support-ticket submission
flow so the UI can react more intelligently to failures (including 429
retry-window messaging).
* Enhanced retry timing extraction for rate-limited errors by using
`Retry-After` with a fallback to rate-limit reset data.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-16 14:58:48 +00:00

164 lines
5.4 KiB
TypeScript

import * as Sentry from '@sentry/nextjs'
import { useFlag } from 'common'
import { Loader2 } from 'lucide-react'
import Link from 'next/link'
import { useCallback, useReducer } from 'react'
import { toast } from 'sonner'
import { Button, cn, Tooltip, TooltipContent, TooltipTrigger } from 'ui'
import { IncidentAdmonition } from './IncidentAdmonition'
import { Success } from './Success'
import type { ExtendedSupportCategories } from './Support.constants'
import { SupportAssistantSuccessCard } from './SupportAssistantSuccessCard'
import { createInitialSupportFormState, supportFormReducer } from './SupportForm.state'
import { NO_PROJECT_MARKER, type SupportFormUrlKeys } from './SupportForm.utils'
import { SupportFormV3 } from './SupportFormV3'
import { useSupportForm } from './useSupportForm'
import { useIncidentStatusQuery } from '@/data/platform/incident-status-query'
import { useStateTransition } from '@/hooks/misc/useStateTransition'
import { useTrack } from '@/lib/telemetry/track'
function useSupportFormTelemetry() {
const track = useTrack()
return useCallback(
({
projectRef,
orgSlug,
category,
}: {
projectRef: string | undefined
orgSlug: string | undefined
category: ExtendedSupportCategories
}) =>
track(
'support_ticket_submitted',
{ ticketCategory: category },
{ project: projectRef, organization: orgSlug }
),
[track]
)
}
interface SupportFormProps {
initialParams?: Partial<SupportFormUrlKeys>
}
export function SupportForm({ initialParams }: SupportFormProps) {
const [state, dispatch] = useReducer(supportFormReducer, undefined, createInitialSupportFormState)
const { form, initialError, projectRef } = useSupportForm(dispatch, initialParams)
const showSupportAssistantFollowUp = useFlag('supportAssistantFollowUp') === true
const {
data: allStatusPageEvents,
isPending: isIncidentsPending,
isError: isIncidentsError,
} = useIncidentStatusQuery()
const { incidents = [] } = allStatusPageEvents ?? {}
const hasActiveIncidents =
!isIncidentsPending && !isIncidentsError && incidents && incidents.length > 0
const sendTelemetry = useSupportFormTelemetry()
useStateTransition(state, 'submitting', 'success', (_, curr) => {
toast.success('Support request sent. Thank you!')
sendTelemetry({
projectRef: curr.sentProjectRef,
orgSlug: curr.sentOrgSlug,
category: curr.sentCategory,
})
})
useStateTransition(state, 'submitting', 'error', (_, curr) => {
toast.error(`Failed to submit support ticket: ${curr.message}`)
if (curr.code !== 429) {
Sentry.captureMessage(`Failed to submit Support Form: ${curr.message}`)
}
dispatch({ type: 'RETURN_TO_EDITING' })
})
const successState = state.type === 'success' ? state : null
const showAssistantSuccessCard =
showSupportAssistantFollowUp &&
successState !== null &&
successState.submittedRequest.projectRef !== undefined &&
successState.submittedRequest.projectRef !== NO_PROJECT_MARKER
return (
<div className="relative h-full overflow-y-auto overflow-x-hidden">
<IncidentAdmonition
isActive={hasActiveIncidents}
className="rounded-none border-x-0 shadow-none"
/>
<div className="min-h-full px-5 pt-5">
<div className="flex flex-col gap-y-8">
{successState ? (
<div className="flex flex-col gap-y-8 pt-2">
<Success
selectedProject={
successState.sentProjectRef === undefined
? (projectRef ?? undefined)
: successState.sentProjectRef
}
sentCategory={successState.sentCategory}
showFinishAction={false}
/>
{showAssistantSuccessCard && (
<SupportAssistantSuccessCard request={successState.submittedRequest} />
)}
</div>
) : (
<SupportFormV3
form={form}
initialError={initialError}
state={state}
dispatch={dispatch}
selectedProjectRef={projectRef}
/>
)}
</div>
</div>
</div>
)
}
export function SupportFormStatusButton() {
const { data: allStatusPageEvents, isPending: isLoading, isError } = useIncidentStatusQuery()
const { incidents = [], maintenanceEvents = [] } = allStatusPageEvents ?? {}
const isMaintenance = maintenanceEvents.length > 0
const isIncident = incidents.length > 0
return (
<Tooltip>
<TooltipTrigger asChild>
<Button
asChild
type="default"
size="tiny"
icon={
isLoading ? (
<Loader2 className="animate-spin" />
) : (
<div className={cn('h-2 w-2 rounded-full', isIncident ? 'bg-warning' : 'bg-brand')} />
)
}
>
<Link href="https://status.supabase.com/" target="_blank" rel="noreferrer">
{isLoading
? 'Checking status'
: isError
? 'Failed to check status'
: isIncident
? 'Active incident ongoing'
: isMaintenance
? 'Scheduled maintenance'
: 'All systems operational'}
</Link>
</Button>
</TooltipTrigger>
<TooltipContent side="bottom" align="center">
Check the Supabase status page
</TooltipContent>
</Tooltip>
)
}