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(auth): capture underlying error when login fails without a JSON body (#77210)

posthog[bot]844408fde9cf
diff --git a/frontend/src/scenes/authentication/login/loginLogic.test.ts b/frontend/src/scenes/authentication/login/loginLogic.test.ts
index ece5f3876f7c..76cc544f1ed6 100644
--- a/frontend/src/scenes/authentication/login/loginLogic.test.ts
+++ b/frontend/src/scenes/authentication/login/loginLogic.test.ts
@@ -1,6 +1,7 @@
import { startAuthentication } from '@simplewebauthn/browser'
import { router } from 'kea-router'
import { expectLogic, testUtilsPlugin } from 'kea-test-utils'
+import posthog from 'posthog-js'
import { removeProjectIdIfPresent } from 'lib/utils/kea-router'
import { handleLoginRedirect, loginLogic } from 'scenes/authentication/login/loginLogic'
@@ -11,6 +12,7 @@ import { useMocks } from '~/mocks/jest'
import { initKeaTests } from '~/test/init'
jest.mock('@simplewebauthn/browser', () => ({ startAuthentication: jest.fn() }))
+jest.mock('posthog-js')
// isWebKitBrowser() reads navigator.vendor: "Apple Computer, Inc." on WebKit, "Google Inc." on Chromium.
const WEBKIT_VENDOR = 'Apple Computer, Inc.'
@@ -208,6 +210,46 @@ describe('loginLogic', () => {
})
})
+ describe('opaque login failure', () => {
+ let logic: ReturnType<typeof loginLogic.build>
+ const originalVendor = window.navigator.vendor
+
+ beforeEach(() => {
+ setVendor(WEBKIT_VENDOR) // skip passkey auto-trigger
+ useMocks({
+ get: { '/api/users/@me/': () => [200, {}] },
+ post: {
+ '/api/login/precheck': () => [200, { saml_available: false }],
+ // A response with no JSON body (a 5xx from the edge, a dropped connection) leaves
+ // `code`/`detail` null on the resulting ApiError.
+ '/api/login': () => [502],
+ },
+ })
+ initKeaTests()
+ router.actions.push('/login')
+ logic = loginLogic()
+ logic.mount()
+ })
+
+ afterEach(() => {
+ logic.unmount()
+ setVendor(originalVendor)
+ jest.clearAllMocks()
+ })
+
+ it('reports the underlying status when code and detail are both null', async () => {
+ logic.actions.setLoginValues({ email: '[email protected]', password: 'a-password' })
+ logic.actions.submitLogin()
+ await expectLogic(logic).toDispatchActions(['submitLoginFailure'])
+
+ expect(logic.values.generalError?.code).toBeFalsy()
+ expect(posthog.captureException).toHaveBeenCalledWith(
+ expect.anything(),
+ expect.objectContaining({ extra: expect.objectContaining({ status: 502 }) })
+ )
+ })
+ })
+
describe('precheck dedupe', () => {
let logic: ReturnType<typeof loginLogic.build>
let precheckHandler: jest.Mock
diff --git a/frontend/src/scenes/authentication/login/loginLogic.ts b/frontend/src/scenes/authentication/login/loginLogic.ts
index 6d5ea3ccbe95..dd2d2a11c525 100644
--- a/frontend/src/scenes/authentication/login/loginLogic.ts
+++ b/frontend/src/scenes/authentication/login/loginLogic.ts
@@ -5,8 +5,10 @@ import type { DeepPartial, DeepPartialMap, FieldName, ValidationErrorType } from
import { loaders } from 'kea-loaders'
import { encodeParams, urlToAction } from 'kea-router'
import { router } from 'kea-router'
+import posthog from 'posthog-js'
import api from 'lib/api'
+import { ApiError } from 'lib/api-error'
import { lemonToast } from 'lib/lemon-ui/LemonToast'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { isWebKitBrowser } from 'lib/utils/dom'
@@ -427,6 +429,14 @@ export const loginLogic = kea<loginLogicType>([
)
throw e
}
+ // A response with no parseable JSON body (a 5xx HTML page, a 502 from the edge, a
+ // dropped connection) leaves code/detail null, so the user gets the generic catch-all
+ // message below. Capture the underlying status/message so these aren't untraceable.
+ if (!code && !detail) {
+ posthog.captureException(e, {
+ extra: { status: (e as ApiError)?.status, message: (e as ApiError)?.message },
+ })
+ }
actions.setGeneralError(code, detail)
throw e
}