Skip to content

fix(hooks): stop reporting 404 errors to PostHog error tracking - #36

Merged
Pratyay360 merged 1 commit into
mainfrom
posthog-self-driving/fixserver-hooks-stop-reporting-d1ad24
Nov 28, 2026
Merged

Pratyay360 merged 1 commit into
mainfrom
posthog-self-driving/fixserver-hooks-stop-reporting-d1ad24

Conversation

@posthog

@posthog posthog Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Problem

  • The team gets a new error tracking exception for each request to a URL that does not exist. Bots, old links and mistyped URLs add noise, and that noise can hide real 5xx errors.
  • handleError in src/hooks.server.ts calls posthog.captureException for every error. When no route matches, SvelteKit sends its "Not Found" error through this hook.
  • Users are not affected. They still get the normal 404 page.

Origin

  • Error tracking: issue
  • First signal: 2026-11-28
  • Inbox report: open
  • Task started by: auto-start, after the report was rated P3 and ready to fix

Changes

  • The hook skips captureException when the caught error has status 404. All other errors are still reported, with the same distinct ID and session properties.
  • The guard reads error.status, not a status argument. This repo runs SvelteKit 3, which sends { kind, error, event } to handleError:
kind error Reported after this change
framework (unmatched route, 405, …) { status, message } Yes, except status 404
app (error(...) helper) App.Error, includes status Yes, except status 404
validation { status: 400, message } Yes
unknown (thrown by code) the thrown value Yes

Warning

Kit 3 adds status to the hook input only in dev, as a deprecated getter. In production it is undefined. A status !== 404 check (the approach in the report) passes in dev but reports every 404 in production.

  • The { message } return value does not change.
  • New unit test src/hooks.server.test.ts covers framework 404, app 404, framework 405 and unknown errors.

Checks

  • vp test run: 12 files, 126 tests pass.
  • vp fmt --check and vp lint on the changed files: pass.
  • svelte-check: 1 error, in MediaPlaceHolder.svelte. This error is also on main. The changed files have no errors. Kit 3 adds types to the hook, so kind and error.status are type-checked.
  • I did not run the full vp check, because main has format failures in files that this PR does not change.

Agent context

  • I did not skip all 4xx errors. A 405 or 400 can come from a real bug in a form or remote function, so the guard skips only 404, the same as the guard that commit 74868ee removed.
  • Not in scope, for a person to decide:
    • Commit 74868ee also removed the better-auth session handle, the security headers, the i18n page transform and the request metrics from this file.
    • The return value sends error.message of unknown errors to the client. For framework and app errors it replaces the safe message (for example "Not Found") with "Internal Error", because those errors are plain objects, not Error instances.

Closes #35


Created with PostHog Desktop from this inbox report.

Closes #35

SvelteKit 3 sends unmatched routes to handleError as a framework error with status 404. The hook reported each one as an exception. Kit 3 does not pass a status argument in production, so the guard reads error.status for all kinds except unknown.

Generated-By: PostHog Desktop
Task-Id: bfe15e03-56da-4779-964f-6a8e014d11f5
@vercel

vercel Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
lightcms Ready Ready Preview Nov 28, 2026 11:23am UTC

@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI (base), Organization UI (inherited)
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c47128fa-3fe7-4a6c-bb42-7905e4513043

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@posthog
posthog Bot requested a review from Pratyay360 November 28, 2026 11:22
@Pratyay360
Pratyay360 marked this pull request as ready for review November 28, 2026 12:17
Copilot AI balanced review requested due to automatic review settings November 28, 2026 12:17
@Pratyay360
Pratyay360 merged commit 3475512 into main Nov 28, 2026
9 of 10 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@coderabbitai

coderabbitai Bot commented Nov 28, 2026

Copy link
Copy Markdown

Add Carrot credits or activate Agent usage billing to use Autofix

This branch was successfully deployed

1 active deployment
Preview — 0c9aaac9 Deployed Nov 28, 2026 by vercel[bot]
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.

fix(server-hooks): Stop reporting SvelteKit 404s as exceptions

2 participants