Repository navigation
Keep expected 4xx client errors out of error tracking - #4
Draft
posthog-eu[bot] wants to merge 1 commit into
Draft
posthog-eu[bot] wants to merge 1 commit into
posthog-eu[bot] wants to merge 1 commit into
Conversation
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
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.
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 viacaptureException(all samplesmechanism.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:
isExpectedClientErrorguard to@leuchtturm/core/errorscoveringUnauthorizedError,ForbiddenError,NotFoundError, andValidationError.captureUnexpectedDefectinobservability.tswhen the defect is an expected client error.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.