Skip to content

[SvelteKit] intentional 4xx errors captured in prefetch #21775

Description

@hyunbinseo

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/sveltekit

SDK Version

10.60.0

Framework Version

No response

Link to Sentry event

No response

Reproduction Example/SDK Setup

https://github.com/hyunbinseo/svelte-kit-templates/tree/sentry-javascript-21775

// src/routes/protected/+page.server.tsimport{error}from'@sveltejs/kit';exportconstload=()=>error(403);
// src/hooks.client.tsimport*asSentryfrom'@sentry/sveltekit';exportconsthandleError=Sentry.handleErrorWithSentry();

Trigger a client-side prefetch to /protected.

Steps to Reproduce

When a +page.server.ts throws error(403) and a client-side prefetch (e.g. hovering <a>) triggers it, handleErrorWithSentry() captures the error in Sentry despite the built-in is4xxError guard.

The resulting event is misleading: instead of a normal exception, Sentry reports a plain object capture.

Expected Result

No Sentry event — is4xxError should suppress it, as it does for full navigations.

Actual Result

A Sentry event is created with:

Type: Error
Value: Object captured as exception with keys: error, status, type

The error field passed to captureException is a SvelteKit plain-object error { type, error, status }, not an Error instance. This indicates is4xxError(input) returned false, allowing the capture to proceed.

Additional Context

The __data.json request itself returns HTTP 200 — the 403 is embedded in the JSON body, not the HTTP status. That means SvelteKit's get_status(error) receives a plain deserialized object, not an HttpError instance, and falls back to returning 500.

HTTP/1.1 200 OK
Vary: Origin
cache-control: private, no-store
content-length: 105
content-type: application/json
Date: Thu, 25 Jun 2026 07:55:40 GMT
Connection: keep-alive
Keep-Alive: timeout=5
{"type":"data","nodes":[{"type":"skip"},{"type":"error","error":{"message":"Error: 403"},"status":403}]}

Priority

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions