: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(data-warehouse): show why saving source credentials failed on the connect page (#117045)
Tom Owers3a033c70014d
diff --git a/products/data_warehouse/frontend/scenes/SourceConnectScene/sourceConnectSceneLogic.test.ts b/products/data_warehouse/frontend/scenes/SourceConnectScene/sourceConnectSceneLogic.test.tsindex 8f3c194867c5..5ac4cd79e850 100644--- a/products/data_warehouse/frontend/scenes/SourceConnectScene/sourceConnectSceneLogic.test.ts+++ b/products/data_warehouse/frontend/scenes/SourceConnectScene/sourceConnectSceneLogic.test.ts@@ -1,4 +1,7 @@import { router } from 'kea-router'+import { expectLogic } from 'kea-test-utils'++import { lemonToast } from 'lib/lemon-ui/LemonToast'import { useMocks } from '~/mocks/jest'import { initKeaTests } from '~/test/init'@@ -82,6 +85,12 @@ describe('sourceConnectSceneLogic', () => {get: {'/api/environments/:team_id/external_data_sources/wizard/': AVAILABLE_SOURCES,},+ post: {+ '/api/projects/:team_id/external_data_sources/store_credentials/': () => [+ 400,+ { message: 'Could not connect to the database. Check the host, then try again.' },+ ],+ },})initKeaTests()unmountAvailableSources = availableSourcesLogic.mount()@@ -125,4 +134,18 @@ describe('sourceConnectSceneLogic', () => {'ba07775f-8eaf-4d09-aa6f-50e37f17f243')})++ it('shows the rejection message when the credentials fail validation', async () => {+ const errorToast = jest.spyOn(lemonToast, 'error').mockReturnValue(undefined as any)+ router.actions.push('/data-warehouse/connect?kind=Postgres')+ sourceConnectSceneLogic.actions.setCredentialsFormValue('payload', { host: 'db.example.com' })++ await expectLogic(sourceConnectSceneLogic, () => {+ sourceConnectSceneLogic.actions.submitCredentialsForm()+ }).toFinishAllListeners()++ expect(errorToast).toHaveBeenCalledWith('Could not connect to the database. Check the host, then try again.')+ expect(sourceConnectSceneLogic.values.storedCredential).toBeNull()+ errorToast.mockRestore()+ })})diff --git a/products/data_warehouse/frontend/scenes/SourceConnectScene/sourceConnectSceneLogic.tsx b/products/data_warehouse/frontend/scenes/SourceConnectScene/sourceConnectSceneLogic.tsxindex 96c654ef1264..bf08f5fde4fe 100644--- a/products/data_warehouse/frontend/scenes/SourceConnectScene/sourceConnectSceneLogic.tsx+++ b/products/data_warehouse/frontend/scenes/SourceConnectScene/sourceConnectSceneLogic.tsx@@ -22,7 +22,7 @@ import { SourceConfigResponseApi } from 'products/warehouse_sources/frontend/genimport type { SourceCredentialApi } from 'products/warehouse_sources/frontend/generated/api.schemas'import { availableSourcesLogic } from '../NewSourceScene/availableSourcesLogic'-import { getErrorsForFields } from '../NewSourceScene/sourceWizardLogic'+import { getErrorsForFields, resolveConnectErrorMessage } from '../NewSourceScene/sourceWizardLogic'// Carries the field whose file failed to read/parse so the submit handler can name it in the toast.class FileUploadParseError extends Error {@@ -224,10 +224,21 @@ export const sourceConnectSceneLogic = kea<sourceConnectSceneLogicType>([)return}- const credential = await externalDataSourcesStoreCredentialsCreate(- String(ApiConfig.getCurrentTeamId()),- { source_type: values.sourceConfig.name, payload }- )+ let credential: SourceCredentialApi+ try {+ credential = await externalDataSourcesStoreCredentialsCreate(String(ApiConfig.getCurrentTeamId()), {+ source_type: values.sourceConfig.name,+ payload,+ })+ } catch (e: any) {+ // The endpoint tests the credentials against a live connection, so a rejection+ // is the common case. kea-forms swallows a thrown submit, leaving the button inert.+ if (e?.status >= 500) {+ posthog.captureException(e)+ }+ lemonToast.error(resolveConnectErrorMessage(e))+ return+ }actions.setStoredCredential(credential)},},