Skip to content

fix(sveltekit): Ensure server errors from streamed responses are sent #17044

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 17, 2025

Conversation

Lms24
Copy link
Member

@Lms24 Lms24 commented Jul 16, 2025

In SvelteKit, users can return a Promise from a load function which causes a streamed http respnse to be sent. If the promise rejects after it is returned and the initial response is sent, an error is thrown server-side. This error will not be captured by our request handler wrappers because at this time, they already finished.

However, the error will be caught via our handleErrorWithSentry hook. This means we actually still catch the error but because the cloudflare function already terminated directly after the rejection, it is not sent successfully (i.e. the good old flush problem).

This PR makes sure we use of Cloudflare's waitUntil function which fortunately is available within the error handler hook.

closes #17009

cursor[bot]

This comment was marked as outdated.

@Lms24 Lms24 self-assigned this Jul 16, 2025
@Lms24 Lms24 requested review from AbhiPrasad, a team and chargome and removed request for a team July 16, 2025 16:32
@Lms24 Lms24 changed the title fix(sveltekit): Ensure errors from streamed responses are sent fix(sveltekit): Ensure server errors from streamed responses are sent Jul 16, 2025
Copy link
Member

@chargome chargome left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@Lms24 Lms24 merged commit dc9238b into develop Jul 17, 2025
35 checks passed
@Lms24 Lms24 deleted the lms/fix-sveltekit-cf-waitUntil-in-handleError branch July 17, 2025 07:32
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.

Errors not properly reported when streaming data fails in Sveltekit on Cloudflare
3 participants