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): explain likely ad blocker when a source connection can't reach the server (#76686)

Tom Owers74fc90560770
diff --git a/products/data_warehouse/frontend/scenes/NewSourceScene/sourceWizardLogic.tsx b/products/data_warehouse/frontend/scenes/NewSourceScene/sourceWizardLogic.tsx
index b478e6037b95..d99d36f5206f 100644
--- a/products/data_warehouse/frontend/scenes/NewSourceScene/sourceWizardLogic.tsx
+++ b/products/data_warehouse/frontend/scenes/NewSourceScene/sourceWizardLogic.tsx
@@ -253,6 +253,23 @@ function webhookResultHasNoPendingInputs(webhookResult: WebhookCreateResult | nu
return !!webhookResult?.success && (webhookResult.pending_inputs?.length ?? 0) === 0
}
+// A thrown fetch has no HTTP status, so its message is the raw "Failed to fetch", most often an ad
+// blocker or extension blocking the request. Name that likely cause instead of echoing it.
+export function resolveConnectErrorMessage(e: any): string {
+ const apiMessage = e?.data?.message ?? e?.detail
+ if (apiMessage) {
+ return apiMessage
+ }
+ if (e?.status === undefined || e?.status === null || e?.status === 0) {
+ return "PostHog couldn't reach the server to set up your source. This is often an ad blocker or browser extension blocking the request. Try pausing it or switching networks, then try again."
+ }
+ if (e?.status >= 500) {
+ return 'PostHog could not validate your connection in time. This can happen with a very large schema or a slow or unreachable database — please check your connection details and try again.'
+ }
+ // A 4xx without a message body would otherwise toast "undefined".
+ return e?.message ?? 'Something went wrong setting up your source. Please try again.'
+}
+
const manualLinkSourceMap: Record<ManualLinkSourceType, string> = {
aws: 'S3',
'google-cloud': 'Google Cloud Storage',
@@ -3302,7 +3319,7 @@ export const sourceWizardLogic = kea<sourceWizardLogicType>([
actions.setStep(5)
}
} catch (e: any) {
- lemonToast.error(e.data?.message ?? e.message)
+ lemonToast.error(resolveConnectErrorMessage(e))
// 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)
@@ -3478,15 +3495,8 @@ export const sourceWizardLogic = kea<sourceWizardLogicType>([
actions.setDatabaseSchemas(schemas)
actions.onNext()
} catch (e: any) {
- // A gateway timeout / 5xx has no JSON body, so e.message is the raw
- // "Non-OK response [POST ...] (status 504: )" — meaningless to the user. Surface a
- // friendly hint for server-side failures while keeping any API-provided message.
const apiMessage = e.data?.message ?? e.detail
- const errorMessage =
- apiMessage ??
- (e.status >= 500
- ? 'PostHog could not validate your connection in time. This can happen with a very large schema or a slow or unreachable database — please check your connection details and try again.'
- : e.message)
+ const errorMessage = resolveConnectErrorMessage(e)
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 2467cc675e84..cd1880cbec61 100644
--- a/products/data_warehouse/frontend/scenes/NewSourceScene/tests/sourceWizardLogic.test.ts
+++ b/products/data_warehouse/frontend/scenes/NewSourceScene/tests/sourceWizardLogic.test.ts
@@ -11,6 +11,7 @@ import {
getDatabaseSchemaPayload,
getErrorsForFields,
mergeRestoredSourceFormValues,
+ resolveConnectErrorMessage,
shouldHydrateSourceFromUrl,
sourceWizardLogic,
} from '../sourceWizardLogic'
@@ -58,6 +59,27 @@ describe('sourceWizardLogic', () => {
expect(shouldHydrateSourceFromUrl(2, postgresSource, postgresSource, 'warehouse', 'direct')).toBe(true)
})
+ describe('resolveConnectErrorMessage', () => {
+ it('guides toward ad blockers when a request never reaches the server', () => {
+ // A thrown fetch has no HTTP status; without this branch the user only sees "Failed to fetch".
+ const message = resolveConnectErrorMessage({ message: 'Failed to fetch', status: undefined })
+ expect(message).toContain('ad blocker')
+ expect(message).not.toEqual('Failed to fetch')
+ })
+
+ it('prefers an API-provided message over the network hint', () => {
+ expect(resolveConnectErrorMessage({ data: { message: 'Invalid credentials' }, status: 400 })).toEqual(
+ 'Invalid credentials'
+ )
+ })
+
+ it('never returns undefined for a 4xx with no message body', () => {
+ const message = resolveConnectErrorMessage({ status: 400 })
+ expect(message).toBeTruthy()
+ expect(message).not.toEqual('undefined')
+ })
+ })
+
describe('getDatabaseSchemaPayload', () => {
it('includes the selected access method for schema discovery', () => {
expect(