Skip to content

Stop reporting handled transient network errors to error tracking#40

Merged
jonbng merged 1 commit into
mainfrom
posthog-code/filter-transient-network-errors
Jul 12, 2026
Merged

Stop reporting handled transient network errors to error tracking#40
jonbng merged 1 commit into
mainfrom
posthog-code/filter-transient-network-errors

Conversation

@posthog-eu

@posthog-eu posthog-eu Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Summary

Transient TypeError: Failed to fetch network failures were showing up as error-tracking issues even though the extension already handles them gracefully. They leaked in because entrypoints/content.tsx monkeypatches console.error and unhandledrejection to forward everything into captureException — so an already-handled, expected network blip became a logged "issue" that buries genuine errors and burns free-tier quota.

  • Downgrade the fetchAllOpgaver failure log from console.error to console.warn (it already returns null and degrades cleanly).
  • Add an isIgnorableNetworkError guard to the catch-all unhandledrejection and console.error forwarders that drops generic transient network failures (Failed to fetch, Firefox's NetworkError when attempting to fetch resource., Safari's Load failed). Explicit captureException() calls elsewhere are untouched, so real failures still get reported.

Why

The team was getting error-tracking noise from two issues (TypeError: Failed to fetch and ... Failed to fetch all opgaver: TypeError: Failed to fetch) that aren't real bugs — the features degrade cleanly and no user sees breakage. This keeps the error-tracking signal clean without hiding genuine failures.


Created with PostHog Code from an inbox report.

Transient `TypeError: Failed to fetch` network failures are already handled
gracefully at their callsites (e.g. `fetchAllOpgaver` degrades to null), but
they still surfaced as error-tracking issues because `entrypoints/content.tsx`
monkeypatches `console.error` and `unhandledrejection` to forward everything
into `captureException`.

- Downgrade the `fetchAllOpgaver` failure log from `console.error` to
  `console.warn` so the handled failure no longer flows through the capture path.
- Add an `isIgnorableNetworkError` guard in the catch-all `unhandledrejection`
  and `console.error` forwarders that drops generic transient network failures
  (`Failed to fetch` / `NetworkError when attempting to fetch resource.` /
  `Load failed`). Explicit `captureException()` calls elsewhere are untouched, so
  real failures still get reported.

Generated-By: PostHog Code
Task-Id: 68411aaa-acab-406d-b78b-0c287537f8ca
@vercel

vercel Bot commented Jul 11, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
betterlectio Ready Ready Preview, Comment Jul 11, 2026 6:17pm
betterlectio-admin Ready Ready Preview, Comment Jul 11, 2026 6:17pm

@jonbng jonbng marked this pull request as ready for review July 12, 2026 10:04
Copilot AI review requested due to automatic review settings July 12, 2026 10:04
@jonbng jonbng merged commit 952f59e into main Jul 12, 2026
5 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR reduces PostHog error-tracking noise by preventing expected transient network failures (e.g. generic “Failed to fetch” across browsers) from being forwarded via the global unhandledrejection / console.error capture paths, while leaving intentional captureException() calls elsewhere unchanged.

Changes:

  • Add an isIgnorableNetworkError filter and apply it to the global unhandledrejection forwarding and console.error monkeypatch in entrypoints/content.tsx.
  • Downgrade fetchAllOpgaver()’s transient failure log from console.error to console.warn to avoid generating error-tracking issues for handled failures.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
entrypoints/content.tsx Adds transient-network-error filtering to global error forwarding and console error capture to avoid reporting handled fetch blips.
components/OpgaverPage.tsx Changes the handled fetch-all failure log to console.warn to avoid being ingested by the global console.error forwarder.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread entrypoints/content.tsx
Comment on lines +716 to +720
const joined = args.map(String).join(' ');
if (
_blConsoleErrorCaptures < MAX_CONSOLE_ERROR_REPORTS &&
!isIgnorableNetworkError(joined) &&
!args.some(isIgnorableNetworkError)
Comment on lines +456 to +458
// Transient network failures here are expected and handled — we degrade to
// an empty list. Use console.warn so the global console.error capture in
// entrypoints/content.tsx doesn't report this as an error-tracking issue.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants