Skip to content

Keep expected 4xx client errors out of error tracking - #4

Draft
posthog-eu[bot] wants to merge 1 commit into
masterfrom
posthog-code/skip-expected-client-errors-in-capture
Draft

posthog-eu[bot] wants to merge 1 commit into
masterfrom
posthog-code/skip-expected-client-errors-in-capture

Conversation

@posthog-eu

@posthog-eu posthog-eu Bot commented Jun 24, 2026

Copy link
Copy Markdown

Summary

A handled, expected 401 was surfacing in PostHog error tracking as a tracked exception. The API auth middleware returns a typed UnauthorizedError (HTTP 401) for any unauthenticated request, but that typed failure could still leak into the observability capture path and be reported via captureException (all samples mechanism.handled=true, no $current_url — a server-side capture, not a real crash).

This filters expected, typed 4xx client errors out of the capture path so only genuine unexpected defects reach error tracking:

  • Adds an isExpectedClientError guard to @leuchtturm/core/errors covering UnauthorizedError, ForbiddenError, NotFoundError, and ValidationError.
  • Short-circuits captureUnexpectedDefect in observability.ts when the defect is an expected client error.
  • Adds unit coverage for the guard.

Why

The leuchtturm team was getting low-volume error-tracking noise from an expected, handled 401 (UnauthorizedError: Unauthorized.) being recorded as an exception. The capture path is meant to report only defects, so an expected 4xx client error reaching error tracking is the bug.


Created with PostHog Code from an inbox report.

The auth middleware returns a typed UnauthorizedError (HTTP 401) for any
unauthenticated request — an expected, handled outcome. That typed failure
could still reach the observability capture path and be reported to PostHog
error tracking as an exception (mechanism.handled=true), producing benign
noise rather than signalling a real defect.

Filter expected, typed 4xx client errors (UnauthorizedError, ForbiddenError,
NotFoundError, ValidationError) out of captureUnexpectedDefect so only genuine
unexpected defects reach captureException. Adds an isExpectedClientError guard
to @leuchtturm/core/errors with unit coverage.

Generated-By: PostHog Code
Task-Id: 4eb073f5-781c-4940-aa9a-cf18f3c034aa
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.

0 participants