Skip to content

The open alternative to Salesforce, designed for AI.

fix(billing): surface checkoutSession GraphQL errors in toast (#27018)

Evan Liu7d187740bb36
diff --git a/packages/twenty-front/src/modules/settings/billing/hooks/useHandleCheckoutSession.ts b/packages/twenty-front/src/modules/settings/billing/hooks/useHandleCheckoutSession.ts
index 1668241a996..a5275558828 100644
--- a/packages/twenty-front/src/modules/settings/billing/hooks/useHandleCheckoutSession.ts
+++ b/packages/twenty-front/src/modules/settings/billing/hooks/useHandleCheckoutSession.ts
@@ -1,7 +1,10 @@
import { useRedirect } from '@/domain-manager/hooks/useRedirect';
+import { getToastOptionsFromError } from '@/error-handler/utils/getToastOptionsFromError';
+import { CombinedGraphQLErrors } from '@apollo/client/errors';
import { useMutation } from '@apollo/client/react';
import { t } from '@lingui/core/macro';
import { useState } from 'react';
+import { isDefined } from 'twenty-shared/utils';
import { useToast } from 'twenty-ui/components/feedback';
import {
type BillingPlanKey,
@@ -47,11 +50,19 @@ export const useHandleCheckoutSession = ({
return;
}
redirect(data.checkoutSession.url);
- } catch {
- enqueueToast({
- variant: 'error',
- children: t`Checkout session error. Please retry or contact Twenty team`,
- });
+ } catch (error) {
+ const toastOptions =
+ CombinedGraphQLErrors.is(error) &&
+ isDefined(error.errors[0]?.extensions?.userFriendlyMessage)
+ ? getToastOptionsFromError({ error })
+ : undefined;
+
+ enqueueToast(
+ toastOptions ?? {
+ variant: 'error',
+ children: t`Checkout session error. Please retry or contact Twenty team`,
+ },
+ );
} finally {
setIsSubmitting(false);
}