The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Fix downgrade network error causing UI crash (#26919)
Joshen Lim4637140e729d
diff --git a/apps/studio/components/interfaces/Integrations/IntegrationConnection.tsx b/apps/studio/components/interfaces/Integrations/IntegrationConnection.tsxindex bcf89ee7ca9..d9854888486 100644--- a/apps/studio/components/interfaces/Integrations/IntegrationConnection.tsx+++ b/apps/studio/components/interfaces/Integrations/IntegrationConnection.tsx@@ -3,9 +3,6 @@ import { useRouter } from 'next/router'import { forwardRef, useCallback, useState } from 'react'import toast from 'react-hot-toast'import {- AlertDescription_Shadcn_,- AlertTitle_Shadcn_,- Alert_Shadcn_,Button,DropdownMenu,DropdownMenuContent,@@ -16,7 +13,6 @@ import {IconLoader,IconRefreshCw,IconTrash,- Modal,} from 'ui'import ConfirmationModal from 'ui-patterns/Dialogs/ConfirmationModal'@@ -27,7 +23,6 @@ import {import { useIntegrationsVercelConnectionSyncEnvsMutation } from 'data/integrations/integrations-vercel-connection-sync-envs-mutation'import type { IntegrationProjectConnection } from 'data/integrations/integrations.types'import { useProjectsQuery } from 'data/projects/projects-query'-import { WarningIcon } from 'ui-patterns/Icons/StatusIcons'interface IntegrationConnectionItemProps extends IntegrationConnectionProps {disabled?: boolean@@ -49,6 +44,8 @@ const IntegrationConnectionItem = forwardRef<HTMLLIElement, IntegrationConnectioconst onConfirm = useCallback(async () => {try {await onDeleteConnection(connection)+ } catch (error) {+ // [Joshen] No need for error handler} finally {setIsOpen(false)}diff --git a/apps/studio/components/interfaces/Organization/BillingSettings/Subscription/ExitSurveyModal.tsx b/apps/studio/components/interfaces/Organization/BillingSettings/Subscription/ExitSurveyModal.tsxindex 3b71e425cb4..0edb1323cfd 100644--- a/apps/studio/components/interfaces/Organization/BillingSettings/Subscription/ExitSurveyModal.tsx+++ b/apps/studio/components/interfaces/Organization/BillingSettings/Subscription/ExitSurveyModal.tsx@@ -30,14 +30,16 @@ const ExitSurveyModal = ({ visible, subscription, projects, onClose }: ExitSurveconst [selectedReasons, dispatchSelectedReasons] = useReducer(reducer, [])const subscriptionUpdateDisabled = useFlag('disableProjectCreationAndUpdate')- const { mutateAsync: sendExitSurvey, isLoading: isSubmittingFeedback } =- useSendDowngradeFeedbackMutation()- const { mutateAsync: updateOrgSubscription, isLoading: isUpdating } =- useOrgSubscriptionUpdateMutation({+ const { mutate: updateOrgSubscription, isLoading: isUpdating } = useOrgSubscriptionUpdateMutation(+ {onError: (error) => {+ resetCaptcha()toast.error(`Failed to downgrade project: ${error.message}`)},- })+ }+ )+ const { mutateAsync: sendExitSurvey, isLoading: isSubmittingFeedback } =+ useSendDowngradeFeedbackMutation()const isSubmitting = isUpdating || isSubmittingFeedbackconst projectsWithComputeDowngrade = projects.filter((project) => {@@ -87,33 +89,35 @@ const ExitSurveyModal = ({ visible, subscription, projects, onClose }: ExitSurve// If compute instance is present within the existing subscription, then a restart will be triggeredif (!slug) return console.error('Slug is required')- try {- await updateOrgSubscription({ slug, tier: 'tier_free' })- resetCaptcha()- } finally {- }-- try {- await sendExitSurvey({- orgSlug: slug,- reasons: selectedReasons.reduce((a, b) => `${a}- ${b}\n`, ''),- message,- exitAction: 'downgrade',- })- } finally {- }-- toast.success(- willPlanDowngradeHappenImmediately- ? hasProjectsWithComputeDowngrade- ? 'Successfully downgraded organization to the Free plan. Your projects are currently restarting to update their compute instances.'- : 'Successfully downgraded organization to the Free plan'- : 'Your organization is scheduled for the downgrade at the end of your current billing cycle',- { duration: hasProjectsWithComputeDowngrade ? 8000 : 4000 }+ updateOrgSubscription(+ { slug, tier: 'tier_free' },+ {+ onSuccess: async () => {+ resetCaptcha()+ try {+ await sendExitSurvey({+ orgSlug: slug,+ reasons: selectedReasons.reduce((a, b) => `${a}- ${b}\n`, ''),+ message,+ exitAction: 'downgrade',+ })+ } catch (error) {+ // [Joshen] In this case we don't raise any errors if the exit survey fails to send since it shouldn't block the user+ } finally {+ toast.success(+ willPlanDowngradeHappenImmediately+ ? hasProjectsWithComputeDowngrade+ ? 'Successfully downgraded organization to the Free plan. Your projects are currently restarting to update their compute instances.'+ : 'Successfully downgraded organization to the Free plan'+ : 'Your organization is scheduled for the downgrade at the end of your current billing cycle',+ { duration: hasProjectsWithComputeDowngrade ? 8000 : 4000 }+ )+ onClose(true)+ window.scrollTo({ top: 0, left: 0, behavior: 'smooth' })+ }+ },+ })-- onClose(true)- window.scrollTo({ top: 0, left: 0, behavior: 'smooth' })}return (diff --git a/apps/studio/components/interfaces/Organization/IntegrationSettings/IntegrationSettings.tsx b/apps/studio/components/interfaces/Organization/IntegrationSettings/IntegrationSettings.tsxindex 3c249821c0c..9c46414d025 100644--- a/apps/studio/components/interfaces/Organization/IntegrationSettings/IntegrationSettings.tsx+++ b/apps/studio/components/interfaces/Organization/IntegrationSettings/IntegrationSettings.tsx@@ -58,7 +58,8 @@ const IntegrationSettings = () => {const onDeleteGitHubConnection = useCallback(async (connection: IntegrationProjectConnection) => {if (!org?.id) {- throw new Error('Organization not found')+ toast.error('Organization not found')+ return}deleteGitHubConnection({diff --git a/apps/studio/components/interfaces/QueryPerformance/IndexAdvisorDisabledState.tsx b/apps/studio/components/interfaces/QueryPerformance/IndexAdvisorDisabledState.tsxindex 523cccf5acb..d1d87531c10 100644--- a/apps/studio/components/interfaces/QueryPerformance/IndexAdvisorDisabledState.tsx+++ b/apps/studio/components/interfaces/QueryPerformance/IndexAdvisorDisabledState.tsx@@ -1,5 +1,6 @@import { ExternalLink } from 'lucide-react'import Link from 'next/link'+import toast from 'react-hot-toast'import { useParams } from 'common'import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'@@ -43,7 +44,9 @@ export const IndexAdvisorDisabledState = () => {version: indexAdvisorExtension.default_version,})}- } finally {+ toast.success('Successfully enabled index advisor!')+ } catch (error: any) {+ toast.error(`Failed to enable index advisor: ${error.message}`)}}diff --git a/apps/studio/components/interfaces/SQLEditor/SQLEditor.tsx b/apps/studio/components/interfaces/SQLEditor/SQLEditor.tsxindex 0475fa40996..23ba9da0235 100644--- a/apps/studio/components/interfaces/SQLEditor/SQLEditor.tsx+++ b/apps/studio/components/interfaces/SQLEditor/SQLEditor.tsx@@ -223,7 +223,8 @@ const SQLEditor = () => {try {const { title } = await generateSqlTitle({ sql })snap.renameSnippet(id, title)- } finally {+ } catch (error) {+ // [Joshen] No error handler required as this happens in the background and not necessary to ping the user}},[generateSqlTitle, snap]diff --git a/apps/studio/components/interfaces/Settings/General/DeleteProjectPanel/DeleteProjectButton.tsx b/apps/studio/components/interfaces/Settings/General/DeleteProjectPanel/DeleteProjectButton.tsxindex 732e9991236..fecb90872f1 100644--- a/apps/studio/components/interfaces/Settings/General/DeleteProjectPanel/DeleteProjectButton.tsx+++ b/apps/studio/components/interfaces/Settings/General/DeleteProjectPanel/DeleteProjectButton.tsx@@ -3,7 +3,6 @@ import { PermissionAction } from '@supabase/shared-types/out/constants'import { useRouter } from 'next/router'import { useEffect, useState } from 'react'import toast from 'react-hot-toast'-import { Button, Input } from 'ui'import { CANCELLATION_REASONS } from 'components/interfaces/Billing/Billing.constants'import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'@@ -11,6 +10,7 @@ import { useSendDowngradeFeedbackMutation } from 'data/feedback/exit-survey-sendimport { useProjectDeleteMutation } from 'data/projects/project-delete-mutation'import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-query'import { useCheckPermissions, useSelectedOrganization } from 'hooks'+import { Button, Input } from 'ui'import TextConfirmModal from 'ui-patterns/Dialogs/TextConfirmModal'export interface DeleteProjectButtonProps {@@ -41,7 +41,8 @@ const DeleteProjectButton = ({ type = 'danger' }: DeleteProjectButtonProps) => {reasons: selectedReasons.reduce((a, b) => `${a}- ${b}\n`, ''),exitAction: 'delete',})- } finally {+ } catch (error) {+ // [Joshen] In this case we don't raise any errors if the exit survey fails to send since it shouldn't block the user}}diff --git a/apps/studio/components/interfaces/Settings/Integrations/GithubIntegration/GithubSection.tsx b/apps/studio/components/interfaces/Settings/Integrations/GithubIntegration/GithubSection.tsxindex 6fe2032fb93..a0c94649e28 100644--- a/apps/studio/components/interfaces/Settings/Integrations/GithubIntegration/GithubSection.tsx+++ b/apps/studio/components/interfaces/Settings/Integrations/GithubIntegration/GithubSection.tsx@@ -76,10 +76,16 @@ const GitHubSection = () => {const onDeleteGitHubConnection = useCallback(async (connection: IntegrationProjectConnection) => {if (isBranchingEnabled) {- if (!projectRef) throw new Error('Project ref not found')+ if (!projectRef) {+ toast.error('Project ref not found')+ return+ }disableBranching({ projectRef, branchIds: previewBranches?.map((branch) => branch.id) })}- if (!org?.id) throw new Error('Organization not found')+ if (!org?.id) {+ toast.error('Organization not found')+ return+ }deleteGitHubConnection({ connectionId: connection.id, organizationId: org.id })},[diff --git a/apps/studio/components/interfaces/Settings/Vault/Secrets/AddNewSecretModal.tsx b/apps/studio/components/interfaces/Settings/Vault/Secrets/AddNewSecretModal.tsxindex 56c1911f0f1..4ac0451435d 100644--- a/apps/studio/components/interfaces/Settings/Vault/Secrets/AddNewSecretModal.tsx+++ b/apps/studio/components/interfaces/Settings/Vault/Secrets/AddNewSecretModal.tsx@@ -57,14 +57,10 @@ const AddNewSecretModal = ({ visible, onClose }: AddNewSecretModalProps) => {connectionString: project?.connectionString,name: values.keyName || undefined,})- if (addKeyRes.error) {- return toast.error(`Failed to create new key: ${addKeyRes.error.message}`)- } else {- encryptionKeyId = addKeyRes[0].id- }+ encryptionKeyId = addKeyRes[0].id}- const res = await addSecret({+ await addSecret({projectRef: project.ref,connectionString: project?.connectionString,name: values.name,@@ -72,13 +68,10 @@ const AddNewSecretModal = ({ visible, onClose }: AddNewSecretModalProps) => {secret: values.secret,key_id: encryptionKeyId,})-- if (!res.error) {- toast.success(`Successfully added new secret ${values.name}`)- onClose()- } else {- toast.error(`Failed to add secret ${values.name}: ${res.error.message}`)- }+ toast.success(`Successfully added new secret ${values.name}`)+ onClose()+ } catch (error: any) {+ // [Joshen] No error handler required as they are all handled within the mutations already} finally {setSubmitting(false)}diff --git a/apps/studio/components/interfaces/Support/SupportForm.tsx b/apps/studio/components/interfaces/Support/SupportForm.tsxindex a2906ac5cc6..6a4beafef72 100644--- a/apps/studio/components/interfaces/Support/SupportForm.tsx+++ b/apps/studio/components/interfaces/Support/SupportForm.tsx@@ -190,7 +190,8 @@ const SupportForm = ({ setSentCategory, setSelectedProject }: SupportFormProps)const authConfig = await getProjectAuthConfig({ projectRef: values.projectRef })payload.siteUrl = authConfig.SITE_URLpayload.additionalRedirectUrls = authConfig.URI_ALLOW_LIST- } finally {+ } catch (error) {+ // [Joshen] No error handler required as fetching these info are nice to haves, not necessary}}diff --git a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.tsx b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.tsxindex cd3d2c01455..171272ed0f2 100644--- a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.tsx+++ b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.tsx@@ -175,6 +175,8 @@ const SidePanelEditor = ({if (payload !== undefined && configuration !== undefined) {try {await saveRow(payload, isNewRecord, configuration, () => {})+ } catch (error) {+ // [Joshen] No error handler required as error is handled within saveRow} finally {resolve()}diff --git a/apps/studio/components/to-be-cleaned/Storage/DeleteBucketModal.tsx b/apps/studio/components/to-be-cleaned/Storage/DeleteBucketModal.tsxindex 60f34b4654e..3f0f88bc4fc 100644--- a/apps/studio/components/to-be-cleaned/Storage/DeleteBucketModal.tsx+++ b/apps/studio/components/to-be-cleaned/Storage/DeleteBucketModal.tsx@@ -57,10 +57,13 @@ const DeleteBucketModal = ({ visible = false, bucket, onClose }: DeleteBucketMod))- toast.success(`Successfully deleted bucket ${bucket!.name}`)+ toast.success(`Successfully deleted bucket ${bucket?.name}`)router.push(`/project/${projectRef}/storage/buckets`)onClose()- } finally {+ } catch (error) {+ toast.success(+ `Successfully deleted bucket ${bucket?.name}. However, there was a problem deleting the policies tied to the bucket. Please review them in the storage policies section`+ )}},})