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(integrations): map raw OAuth callback errors to friendly copy (#67039)

Tom Owers3c6a4e8c08c0
diff --git a/frontend/src/lib/integrations/integrationsLogic.ts b/frontend/src/lib/integrations/integrationsLogic.ts
index 358107b60ccc..0d3fa313d1d0 100644
--- a/frontend/src/lib/integrations/integrationsLogic.ts
+++ b/frontend/src/lib/integrations/integrationsLogic.ts
@@ -7,6 +7,7 @@ import { LemonDialog, lemonToast } from '@posthog/lemon-ui'
import api, { ApiError, getCookie } from 'lib/api'
import { globalSetupLogic } from 'lib/components/ProductSetup'
import { describeGithubSetupError, GITHUB_INSTALL_PENDING_MESSAGE } from 'lib/integrations/githubSetupErrors'
+import { describeOAuthCallbackError } from 'lib/integrations/oauthCallbackErrors'
import { isKeyOf } from 'lib/utils/guards'
import { fromParamsGivenUrl } from 'lib/utils/url'
import { preflightLogic } from 'scenes/PreflightCheck/preflightLogic'
@@ -228,7 +229,7 @@ export const integrationsLogic = kea<integrationsLogicType>([
let replaceUrl: string = next || urls.settings('project-integrations')
if (error) {
- lemonToast.error(`Failed due to "${error}"`)
+ lemonToast.error(describeOAuthCallbackError(String(error)))
router.actions.replace(replaceUrl)
return
}
diff --git a/frontend/src/lib/integrations/oauthCallbackErrors.test.ts b/frontend/src/lib/integrations/oauthCallbackErrors.test.ts
new file mode 100644
index 000000000000..37c36613b088
--- /dev/null
+++ b/frontend/src/lib/integrations/oauthCallbackErrors.test.ts
@@ -0,0 +1,24 @@
+import { describeOAuthCallbackError } from './oauthCallbackErrors'
+
+describe('describeOAuthCallbackError', () => {
+ // Pins the exact copy that reaches users for every mapped code — the whole point of the module.
+ it.each([
+ ['access_denied', 'Authorization was canceled. Please try connecting again and approve access to continue.'],
+ [
+ 'user_connector_authorize',
+ 'Authorization was not completed. Please try connecting again and approve access to continue.',
+ ],
+ [
+ 'invalid_scope',
+ 'The connection was missing required permissions. Please try connecting again and grant all requested access.',
+ ],
+ ['server_error', 'The provider had a problem completing the connection. Please try again in a moment.'],
+ ['temporarily_unavailable', 'The provider is temporarily unavailable. Please try again in a moment.'],
+ ])('maps %s to actionable copy', (code, expected) => {
+ expect(describeOAuthCallbackError(code)).toBe(expected)
+ })
+
+ it('falls back to the raw code for unknown errors so support can identify them', () => {
+ expect(describeOAuthCallbackError('some_unmapped_code')).toBe('Failed due to "some_unmapped_code"')
+ })
+})
diff --git a/frontend/src/lib/integrations/oauthCallbackErrors.ts b/frontend/src/lib/integrations/oauthCallbackErrors.ts
new file mode 100644
index 000000000000..eed16a82e52d
--- /dev/null
+++ b/frontend/src/lib/integrations/oauthCallbackErrors.ts
@@ -0,0 +1,18 @@
+// Maps raw OAuth error codes that providers return in the callback `?error=` param to messages a
+// user can act on. Ad-platform sources (LinkedIn, Meta, Google Ads) route through the generic
+// integration callback, so without this the user sees cryptic codes like `access_denied` or
+// `user_connector_authorize` verbatim. Unknown codes fall back to the raw value so support can
+// still identify them.
+const OAUTH_CALLBACK_ERROR_MESSAGES: Record<string, string> = {
+ access_denied: 'Authorization was canceled. Please try connecting again and approve access to continue.',
+ user_connector_authorize:
+ 'Authorization was not completed. Please try connecting again and approve access to continue.',
+ invalid_scope:
+ 'The connection was missing required permissions. Please try connecting again and grant all requested access.',
+ server_error: 'The provider had a problem completing the connection. Please try again in a moment.',
+ temporarily_unavailable: 'The provider is temporarily unavailable. Please try again in a moment.',
+}
+
+export function describeOAuthCallbackError(error: string): string {
+ return OAUTH_CALLBACK_ERROR_MESSAGES[error] ?? `Failed due to "${error}"`
+}