fix(toolbar): stop reporting transient network errors as exceptions#66393
Draft
posthog[bot] wants to merge 2 commits into
Draft
fix(toolbar): stop reporting transient network errors as exceptions#66393posthog[bot] wants to merge 2 commits into
posthog[bot] wants to merge 2 commits into
Conversation
toolbarApi.request caught network-level fetch rejections and reported them to
error tracking via captureToolbarException({ reason: 'network' }). Transient
failures (offline, CORS, Safari's "Load failed") are an expected outcome, not a
bug — the caller already soft-fails on the returned result. Treat them like
auth/4xx errors: log them but don't capture them as exceptions. Both the initial
and token-refresh-retry fetch paths throw into this same catch, so both are
covered.
Generated-By: PostHog Code
Task-Id: 19761b2b-f486-409e-a423-58eb482ac959
Contributor
|
Size Change: 0 B Total Size: 64.3 MB ℹ️ View Unchanged
|
…pture Generated-By: PostHog Code Task-Id: 19761b2b-f486-409e-a423-58eb482ac959
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A single Safari user hit a transient "Load failed" network error while the toolbar loaded experiments, and our toolbar API wrapper reported it to error tracking as a brand-new exception. When the experiments tab mounts it calls
getExperiments(), which fetches/api/projects/@current/web_experiments/throughtoolbarApi→toolbarFetch→safeFetch. On a flaky connection Safari throwsTypeError: Load failed;toolbarApi.requestcaught it and deliberately calledcaptureToolbarException(..., { reason: 'network' }).This is noise, not a broken flow — the loader soft-fails gracefully (returns the existing experiments list), so nothing visibly breaks. The only cost is error-tracking triage attention for an offline blip.
Changes
Treat transient network failures as an expected outcome instead of an exception, exactly like auth (401/403) and client (4xx) errors already are: the network catch in
toolbarApi.requestnow logs the failure (downgraded towarn) and returns the sameisNetworkErrorfailure result, but no longer reports it to error tracking. The token-refresh retry fetch throws into this same catch, so both fetch attempts are covered. Updated the surrounding docstrings to match.This mirrors the convention the preloaded-flags path already follows (
index.test.ts: "reports only genuine errors as exceptions"). Genuine 5xx and malformed-JSON failures are still captured.How did you test this code?
I'm an agent — no manual testing. Added
frontend/src/toolbar/toolbarApi.test.tswith two cases and ran them with jest (both pass), plus re-ran the existingindex.test.ts/utils.test.tstoolbar suites (39 passing, no regressions). The new tests guard the regression this PR fixes: a network-level fetch rejection must not callcaptureToolbarException, while a genuine 503 still must — so anyone who re-adds the network capture trips the suite.Automatic notifications
🤖 Agent context
Autonomy: Fully autonomous
Triggered from a PostHog inbox report (P4 noise-reduction). Investigated the
toolbarApi→toolbarFetch→safeFetchchain and confirmed the report's root-cause analysis:safeFetchlets a nativefetch()rejection propagate, andrequest's network catch was the thing reporting it.Chose the targeted fix — gate the capture in
requestrather than swallow the throw insidesafeFetch. Rejected thesafeFetch-returns-a-synthetic-Response approach because any synthetic status either lands in the 5xx branch (which would still capture, defeating the point) or masks theisNetworkErrordistinction callers rely on. Keeping the throw and gating at the single existing network-error site is smaller and preserves the discriminated-union contract. Invoked the/writing-testsskill before adding the test.Created with PostHog Code from an inbox report.