: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(queries): guard against an empty query response (#118520)
posthog[bot]e733e84543a1
diff --git a/frontend/src/queries/query.test.ts b/frontend/src/queries/query.test.tsindex 2b4f07f4f914..e742e96ea427 100644--- a/frontend/src/queries/query.test.ts+++ b/frontend/src/queries/query.test.ts@@ -516,6 +516,19 @@ describe('query', () => {})})+ it('throws a readable ApiError when the query endpoint returns no content', async () => {+ jest.spyOn(api, 'query').mockResolvedValueOnce(null as any)++ const promise = performQuery(+ { kind: NodeKind.EventsQuery, select: ['*'] } as EventsQuery,+ undefined,+ 'blocking'+ )+ await expect(promise).rejects.toBeInstanceOf(ApiError)+ await expect(promise).rejects.toMatchObject({ detail: expect.stringContaining('empty response') })+ jest.restoreAllMocks()+ })+describe('transient query submission failures', () => {const query = { kind: NodeKind.EventsQuery, select: ['*'] } as EventsQueryconst refused = (): ApiError => new ApiError('', 503, undefined, {})diff --git a/frontend/src/queries/query.ts b/frontend/src/queries/query.tsindex 120ed3860355..fe4f70e6300c 100644--- a/frontend/src/queries/query.ts+++ b/frontend/src/queries/query.ts@@ -324,6 +324,12 @@ async function executeQuery<N extends DataNode>()})+ // A successful response with no content (such as a 204) parses to null.+ if (!response) {+ const message = 'The server returned an empty response. Try again.'+ throw new ApiError(message, undefined, undefined, { detail: message })+ }+if (response.detail) {throw new Error(response.detail)}