Repository navigation
fix(hooks): stop reporting 404 errors to PostHog error tracking - #36
Conversation
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
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedBot user detected. To trigger a single review, invoke the
|
There was a problem hiding this comment.
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.
|
Add Carrot credits or activate Agent usage billing to use Autofix |
Problem
handleErrorinsrc/hooks.server.tscallsposthog.captureExceptionfor every error. When no route matches, SvelteKit sends its "Not Found" error through this hook.Origin
Changes
captureExceptionwhen the caught error has status 404. All other errors are still reported, with the same distinct ID and session properties.error.status, not astatusargument. This repo runs SvelteKit 3, which sends{ kind, error, event }tohandleError:kinderrorframework(unmatched route, 405, …){ status, message }app(error(...)helper)App.Error, includesstatusvalidation{ status: 400, message }unknown(thrown by code)Warning
Kit 3 adds
statusto the hook input only in dev, as a deprecated getter. In production it isundefined. Astatus !== 404check (the approach in the report) passes in dev but reports every 404 in production.{ message }return value does not change.src/hooks.server.test.tscovers framework 404, app 404, framework 405 and unknown errors.Checks
vp test run: 12 files, 126 tests pass.vp fmt --checkandvp linton the changed files: pass.svelte-check: 1 error, inMediaPlaceHolder.svelte. This error is also onmain. The changed files have no errors. Kit 3 adds types to the hook, sokindanderror.statusare type-checked.vp check, becausemainhas format failures in files that this PR does not change.Agent context
74868eeremoved.74868eealso removed the better-auth session handle, the security headers, the i18n page transform and the request metrics from this file.error.messageof 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, notErrorinstances.Closes #35
Created with PostHog Desktop from this inbox report.
Closes #35