Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(data-warehouse): keep a failed connection error on screen in the source wizard (#101371)

Tom Owers511459e2ddd9
diff --git a/products/data_warehouse/frontend/scenes/NewSourceScene/NewSourceScene.tsx b/products/data_warehouse/frontend/scenes/NewSourceScene/NewSourceScene.tsx
index 6113ec345a44..3dbff287f90f 100644
--- a/products/data_warehouse/frontend/scenes/NewSourceScene/NewSourceScene.tsx
+++ b/products/data_warehouse/frontend/scenes/NewSourceScene/NewSourceScene.tsx
@@ -238,6 +238,7 @@ function InternalSourcesWizard(props: NewSourcesWizardProps): JSX.Element {
source,
sourceConnectionDetails,
isWebhookFieldInputsSubmitting,
+ connectError,
} = useValues(sourceWizardLogic)
const { onBack, onSubmit, onClear, setInitialConnector, setSourceConnectionDetailsValue, updateSource } =
useActions(sourceWizardLogic)
@@ -376,6 +377,12 @@ function InternalSourcesWizard(props: NewSourcesWizardProps): JSX.Element {
<FreeHistoricalSyncsBanner hideGetStarted={true} />
)}
+ {connectError && currentStep !== 1 && (
+ <LemonBanner type="error" className="mb-4">
+ {connectError}
+ </LemonBanner>
+ )}
+
{currentStep === 1 ? (
<FirstStep allowedSources={props.allowedSources} />
) : currentStep === 2 ? (
diff --git a/products/data_warehouse/frontend/scenes/NewSourceScene/sourceWizardLogic.tsx b/products/data_warehouse/frontend/scenes/NewSourceScene/sourceWizardLogic.tsx
index 7b858d1e8fc6..ce275ff50a73 100644
--- a/products/data_warehouse/frontend/scenes/NewSourceScene/sourceWizardLogic.tsx
+++ b/products/data_warehouse/frontend/scenes/NewSourceScene/sourceWizardLogic.tsx
@@ -433,6 +433,7 @@ export interface sourceWizardLogicValues {
} | null
cdcSelfManagedVerifyResultLoading: boolean
configuredSchemaName: string | null
+ connectError: string | null
connectors: SourceConfigResponseApi[]
currentStep: number
currentSyncMethodModalSchema: ExternalDataSourceSyncSchema | null
@@ -673,6 +674,9 @@ export interface sourceWizardLogicActions {
accessMethod: 'direct' | 'warehouse' | undefined
connector: SourceConfigResponseApi | null
}
+ setConnectError: (message: string | null) => {
+ message: string | null
+ }
setDatabaseSchemas: (schemas: ExternalDataSourceSyncSchema[]) => {
schemas: ExternalDataSourceSyncSchema[]
}
@@ -1055,6 +1059,7 @@ export const sourceWizardLogic = kea<sourceWizardLogicType>([
}),
createSource: true,
setIsLoading: (isLoading: boolean) => ({ isLoading }),
+ setConnectError: (message: string | null) => ({ message }),
setSourceId: (id: string) => ({ sourceId: id }),
closeWizard: true,
cancelWizard: true,
@@ -1294,6 +1299,20 @@ export const sourceWizardLogic = kea<sourceWizardLogicType>([
setIsLoading: (_, { isLoading }) => isLoading,
},
],
+ // The toast that also carries this message is gone in a few seconds, so people retry the
+ // same rejected credentials. Keep the reason next to the form until the next attempt.
+ connectError: [
+ null as string | null,
+ {
+ setConnectError: (_, { message }) => message,
+ getDatabaseSchemas: () => null,
+ createSource: () => null,
+ onBack: () => null,
+ onClear: () => null,
+ selectConnector: () => null,
+ setInitialConnector: () => null,
+ },
+ ],
sourceId: [
null as string | null,
{
@@ -2235,7 +2254,9 @@ export const sourceWizardLogic = kea<sourceWizardLogicType>([
actions.setStep(5)
}
} catch (e: any) {
- lemonToast.error(resolveConnectErrorMessage(e))
+ const connectErrorMessage = resolveConnectErrorMessage(e)
+ actions.setConnectError(connectErrorMessage)
+ lemonToast.error(connectErrorMessage)
// Surface the failure instead of leaving it as a toast-only dead end: a captured
// exception keeps the stack triageable, and the event closes the connect funnel.
posthog.captureException(e)
@@ -2449,6 +2470,7 @@ export const sourceWizardLogic = kea<sourceWizardLogicType>([
} catch (e: any) {
const apiMessage = e.data?.message ?? e.detail
const errorMessage = resolveConnectErrorMessage(e)
+ actions.setConnectError(errorMessage)
lemonToast.error(errorMessage)
// A 5xx with no body is an unexpected server failure, not a user credential
diff --git a/products/data_warehouse/frontend/scenes/NewSourceScene/tests/sourceWizardLogic.test.ts b/products/data_warehouse/frontend/scenes/NewSourceScene/tests/sourceWizardLogic.test.ts
index 16e74b15636d..28460378ecb3 100644
--- a/products/data_warehouse/frontend/scenes/NewSourceScene/tests/sourceWizardLogic.test.ts
+++ b/products/data_warehouse/frontend/scenes/NewSourceScene/tests/sourceWizardLogic.test.ts
@@ -1302,4 +1302,55 @@ describe('sourceWizardLogic', () => {
}
})
})
+
+ describe('connectError', () => {
+ const stripeSource = buildSourceConfig({ name: 'Stripe' })
+
+ afterEach(() => {
+ jest.restoreAllMocks()
+ })
+
+ it('keeps a rejected connection message until the next attempt', async () => {
+ jest.spyOn(api.externalDataSources, 'database_schema').mockRejectedValue({
+ status: 400,
+ data: { message: 'Your API key is invalid or expired.' },
+ })
+
+ const logic = sourceWizardLogic({ availableSources: { Stripe: stripeSource } })
+ const unmount = logic.mount()
+
+ try {
+ logic.actions.selectConnector(stripeSource)
+ await expectLogic(logic, () => logic.actions.getDatabaseSchemas()).toFinishAllListeners()
+ expect(logic.values.connectError).toBe('Your API key is invalid or expired.')
+
+ jest.spyOn(api.externalDataSources, 'database_schema').mockResolvedValue([])
+ await expectLogic(logic, () => logic.actions.getDatabaseSchemas()).toFinishAllListeners()
+ expect(logic.values.connectError).toBeNull()
+ } finally {
+ unmount()
+ }
+ })
+
+ it('drops the message when another source is picked', async () => {
+ jest.spyOn(api.externalDataSources, 'database_schema').mockRejectedValue({
+ status: 400,
+ data: { message: 'Your API key is invalid or expired.' },
+ })
+
+ const logic = sourceWizardLogic({ availableSources: { Stripe: stripeSource } })
+ const unmount = logic.mount()
+
+ try {
+ logic.actions.selectConnector(stripeSource)
+ await expectLogic(logic, () => logic.actions.getDatabaseSchemas()).toFinishAllListeners()
+ expect(logic.values.connectError).toBe('Your API key is invalid or expired.')
+
+ logic.actions.selectConnector(null)
+ expect(logic.values.connectError).toBeNull()
+ } finally {
+ unmount()
+ }
+ })
+ })
})