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(endpoints): show not-found state for missing endpoints (#126323)

posthog[bot]3d6e55dc6670
diff --git a/products/endpoints/frontend/EndpointScene.tsx b/products/endpoints/frontend/EndpointScene.tsx
index 4b4dba5b42d4..0d0d08cdd793 100644
--- a/products/endpoints/frontend/EndpointScene.tsx
+++ b/products/endpoints/frontend/EndpointScene.tsx
@@ -22,6 +22,7 @@ import {
import { LemonBanner, LemonDialog, LemonDivider } from '@posthog/lemon-ui'
import { ActivityLog } from 'lib/components/ActivityLog/ActivityLog'
+import { NotFound } from 'lib/components/NotFound'
import { SceneMenuBarFileItems } from 'lib/components/Scenes/SceneMenuBarFileItems'
import { SceneTags } from 'lib/components/Scenes/SceneTags'
import { SceneTagsCombobox } from 'lib/components/Scenes/SceneTagsCombobox'
@@ -69,7 +70,8 @@ export const scene: SceneExport = {
}
export function EndpointScene(): JSX.Element {
- const { endpoint, endpointLoading, activeTab, viewingVersion, isMaterialized } = useValues(endpointSceneLogic)
+ const { endpoint, endpointLoading, endpointMissing, activeTab, viewingVersion, isMaterialized } =
+ useValues(endpointSceneLogic)
const { setViewingVersion, toggleMaterializationFromMenu } = useActions(endpointSceneLogic)
const { deleteEndpoint, confirmToggleActive, saveTagsInline } = useActions(endpointLogic)
const { versions } = useValues(endpointLogic)
@@ -83,6 +85,10 @@ export function EndpointScene(): JSX.Element {
activeTab === EndpointTab.LINEAGE && endpoint && !lineageSavedQueryId ? EndpointTab.QUERY : activeTab
const sceneMenuBarEnabled = !!featureFlags[FEATURE_FLAGS.SCENE_MENU_BAR]
+ if (endpointMissing) {
+ return <NotFound object="endpoint" />
+ }
+
const tabs: LemonTab<EndpointTab>[] = [
{
key: EndpointTab.QUERY,
diff --git a/products/endpoints/frontend/endpointLogic.test.ts b/products/endpoints/frontend/endpointLogic.test.ts
index c121540fe843..8e04a0460b6b 100644
--- a/products/endpoints/frontend/endpointLogic.test.ts
+++ b/products/endpoints/frontend/endpointLogic.test.ts
@@ -1,6 +1,6 @@
import { router } from 'kea-router'
-import api from 'lib/api'
+import api, { ApiError } from 'lib/api'
import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'
import { urls } from 'scenes/urls'
@@ -9,16 +9,29 @@ import { expectLogic } from '~/test/keaTestUtils'
import { endpointLogic } from './endpointLogic'
-jest.mock('lib/api', () => ({
- __esModule: true,
- default: {
- endpoint: {
- delete: jest.fn(),
- list: jest.fn().mockResolvedValue({ results: [] }),
- update: jest.fn(),
+jest.mock('lib/api', () => {
+ class ApiError extends Error {
+ status?: number
+
+ constructor(message?: string, status?: number) {
+ super(message)
+ this.status = status
+ }
+ }
+
+ return {
+ __esModule: true,
+ default: {
+ endpoint: {
+ delete: jest.fn(),
+ get: jest.fn(),
+ list: jest.fn().mockResolvedValue({ results: [] }),
+ update: jest.fn(),
+ },
},
- },
-}))
+ ApiError,
+ }
+})
jest.mock('lib/lemon-ui/LemonToast/LemonToast', () => ({
lemonToast: { success: jest.fn(), error: jest.fn() },
@@ -30,6 +43,20 @@ describe('endpointLogic', () => {
initKeaTests()
})
+ it.each([
+ ['a missing endpoint', 404, true, 'loadEndpointSuccess'],
+ ['a server failure', 500, false, 'loadEndpointFailure'],
+ ])('handles %s', async (_, status, endpointMissing, expectedAction) => {
+ ;(api.endpoint.get as jest.Mock).mockRejectedValue(new ApiError('No endpoint', status))
+ const logic = endpointLogic()
+ logic.mount()
+
+ await expectLogic(logic, () => logic.actions.loadEndpoint('example-endpoint'))
+ .toDispatchActions([expectedAction])
+ .toFinishAllListeners()
+ .toMatchValues({ endpoint: null, endpointLoading: false, endpointMissing })
+ })
+
it('shows the API detail when an endpoint update fails', async () => {
;(api.endpoint.update as jest.Mock).mockRejectedValue({
detail: 'Cannot materialize endpoint. Reason: The referenced table does not exist.',
diff --git a/products/endpoints/frontend/endpointLogic.tsx b/products/endpoints/frontend/endpointLogic.tsx
index 8e9e12d1b35c..95f8cb602bc8 100644
--- a/products/endpoints/frontend/endpointLogic.tsx
+++ b/products/endpoints/frontend/endpointLogic.tsx
@@ -2,7 +2,7 @@ import { MakeLogicType, actions, connect, kea, listeners, path, reducers } from
import { loaders } from 'kea-loaders'
import { router } from 'kea-router'
-import api from 'lib/api'
+import api, { ApiError } from 'lib/api'
import { SetupTaskId, globalSetupLogic } from 'lib/components/ProductSetup'
import { LemonDialog } from 'lib/lemon-ui/LemonDialog'
import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'
@@ -31,6 +31,7 @@ export interface endpointLogicValues {
endpoint: EndpointVersionType | null
endpointDescription: string | null
endpointLoading: boolean
+ endpointMissing: boolean
endpointName: string | null
isUpdateMode: boolean
materializationStatus: EndpointType['materialization'] | null
@@ -145,6 +146,9 @@ export interface endpointLogicActions {
setEndpointDescription: (endpointDescription: string | null) => {
endpointDescription: string | null
}
+ setEndpointMissing: () => {
+ value: true
+ }
setEndpointName: (endpointName: string) => {
endpointName: string
}
@@ -248,6 +252,7 @@ export const endpointLogic = kea<endpointLogicType>([
deleteEndpointFailure: (errorObject?: any) => ({ errorObject }),
confirmToggleActive: (endpoint: EndpointType) => ({ endpoint }),
saveTagsInline: (tags: string[]) => ({ tags }),
+ setEndpointMissing: true,
}),
reducers({
endpointName: [null as string | null, { setEndpointName: (_, { endpointName }) => endpointName }],
@@ -309,6 +314,13 @@ export const endpointLogic = kea<endpointLogicType>([
loadEndpoint: () => [],
},
],
+ endpointMissing: [
+ false,
+ {
+ loadEndpoint: () => false,
+ setEndpointMissing: () => true,
+ },
+ ],
// Extend the loader reducer to clear on action
materializationStatus: [
null as EndpointType['materialization'] | null,
@@ -325,7 +337,15 @@ export const endpointLogic = kea<endpointLogicType>([
if (!name) {
return null
}
- return await api.endpoint.get(name)
+ try {
+ return await api.endpoint.get(name)
+ } catch (error) {
+ if (error instanceof ApiError && error.status === 404) {
+ actions.setEndpointMissing()
+ return null
+ }
+ throw error
+ }
},
},
],
diff --git a/products/endpoints/frontend/endpointSceneLogic.tsx b/products/endpoints/frontend/endpointSceneLogic.tsx
index 6d1ec49ee4fc..9eeac8188575 100644
--- a/products/endpoints/frontend/endpointSceneLogic.tsx
+++ b/products/endpoints/frontend/endpointSceneLogic.tsx
@@ -128,6 +128,7 @@ export interface MaterializationPreview {
export interface endpointSceneLogicValues {
endpoint: EndpointVersionType | null // endpointLogic
endpointLoading: boolean // endpointLogic
+ endpointMissing: boolean // endpointLogic
activeTab: EndpointTab
breadcrumbs: Breadcrumb[]
bucketOverrides: Record<string, string>
@@ -344,7 +345,7 @@ export const endpointSceneLogic = kea<endpointSceneLogicType>([
'updateEndpointSuccess',
],
],
- values: [endpointLogic(), ['endpoint', 'endpointLoading']],
+ values: [endpointLogic(), ['endpoint', 'endpointLoading', 'endpointMissing']],
})),
actions({
setLocalQuery: (query: Node | null) => ({ query }),