: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(nav): keep the project list when an organization refresh fails (#96529)
posthog[bot]31d7f4569b2b
diff --git a/frontend/src/scenes/organizationLogic.test.ts b/frontend/src/scenes/organizationLogic.test.tsindex 387f15a2ac5c..66939d206d5c 100644--- a/frontend/src/scenes/organizationLogic.test.ts+++ b/frontend/src/scenes/organizationLogic.test.ts@@ -2,9 +2,10 @@ import { MOCK_DEFAULT_ORGANIZATION } from 'lib/api.mock'import { expectLogic } from 'kea-test-utils'+import { useMocks } from '~/mocks/jest'import { initKeaTests } from '~/test/init'-import { AppContext } from '../types'+import { AppContext, OrganizationType } from '../types'import { organizationLogic } from './organizationLogic'describe('organizationLogic', () => {@@ -78,4 +79,42 @@ describe('organizationLogic', () => {})})})+ describe('when a refresh of the organization fails', () => {+ const ORGANIZATION_WITH_TEAMS = {+ ...MOCK_DEFAULT_ORGANIZATION,+ teams: [+ { id: 1, name: 'Project one' },+ { id: 2, name: 'Project two' },+ ],+ } as unknown as OrganizationType++ beforeEach(() => {+ window.POSTHOG_APP_CONTEXT = {+ current_user: { organization: ORGANIZATION_WITH_TEAMS },+ } as unknown as AppContext+ initKeaTests()+ logic = organizationLogic()+ logic.mount()+ })++ it('keeps the organization it already has when the server errors', async () => {+ useMocks({ get: { '/api/organizations/@current': () => [500, { detail: 'nope' }] } })+ await expectLogic(logic).toDispatchActions(['loadCurrentOrganizationSuccess'])++ logic.actions.loadCurrentOrganization()++ await expectLogic(logic).toDispatchActions(['loadCurrentOrganizationSuccess'])+ expect(logic.values.currentOrganization).toEqual(ORGANIZATION_WITH_TEAMS)+ })++ it('drops the organization when the server says it is out of reach', async () => {+ useMocks({ get: { '/api/organizations/@current': () => [403, { detail: 'nope' }] } })+ await expectLogic(logic).toDispatchActions(['loadCurrentOrganizationSuccess'])++ logic.actions.loadCurrentOrganization()++ await expectLogic(logic).toDispatchActions(['loadCurrentOrganizationSuccess'])+ expect(logic.values.currentOrganization).toBeNull()+ })+ })})diff --git a/frontend/src/scenes/organizationLogic.tsx b/frontend/src/scenes/organizationLogic.tsxindex b1ed90140be6..43dde60d098c 100644--- a/frontend/src/scenes/organizationLogic.tsx+++ b/frontend/src/scenes/organizationLogic.tsx@@ -235,8 +235,16 @@ export const organizationLogic = kea<organizationLogicType>([}try {return await api.get('api/organizations/@current')- } catch {- return null+ } catch (error) {+ if (error instanceof ApiError && error.status && error.status < 500) {+ // The organization is gone or out of reach, so let the+ // unavailable-organization screen take over.+ return null+ }+ // A transient failure keeps the organization we already have. Dropping it leaves+ // every reader of `currentOrganization.teams` with nothing for the rest of the+ // session, which is why the project switcher then lists one project.+ return values.currentOrganization}},createOrganization: async (name: string) => {