-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Error Pages with streamed responses always reporting as 200. #12987
Comments
This is how SvelteKit's client-side routing works. The load function response received from the server will always be 200 but the actual response body itself contains the real status code: {
"type": "data",
"nodes": [
{
"type": "skip"
},
{
"type": "skip"
},
{
"type": "error",
"error": {
"message": "Bugged Reports as 200"
},
"status": 500
}
]
} If you disable CSR, you'll see the 500 status codes being logged in the network tab and hook. There's also currently a PR to allow |
Sorry I originally found this bug while trying to debug preloadData, and conflated my two problems thinking one was causing the other since they are so similar. This is happening on SSR as well. If I hit this page from postman it will report back as 200 despite being 500. Currently all of my 404 pages are reporting back as 200. Look at the console.log from the server hook. nonBugged page reports the response correctly as 500, but the bugged one says 200 with the only difference between the 2 being a promise that returns nothing. This has been causing me a ton of problems with my telemetry as a lot of my errors cannot be found on the server and instead showing as ok responses. Also, I would think this would have some bad implications for SEO since all of my pages regardless of if they exist or not are returning 200. This definitely seems like a bug to me at the very least it is extremely unintuitive and should be documented. I would not expect streaming a response to completely change how SvelteKit reports the error on the server when requesting an html page. I would expect it when requesting data.json. |
I can't seem to reproduce this in the given reproduction with CSR disabled. Can you create another reproduction for this specific scenario? |
Apologies for the bad repro I probably should have just made a repo to start as my computer has problems running web containers. https://github.com/bertybot/kit-bug-error-code I made a repro here. In more research it seems like I was wrong with it happening on pages with promises if csr is disabled. It seems to happen when the page has a layout that returns a streamed promise. The page is reported incorrectly even if you go there without CSR. |
Seems like we can't return a 500 here because the layout data needs to be streamed for the error page. Hence, we need to send a 200 response status ahead of time before streaming the data. Is this correct? @dummdidumm |
Describe the bug
When creating a page with streamed responses in the load, whether it is in a parent layout or the page itself, the page will always return a 200 regardless of errors thrown.
Error pages will still function and report $page.status correctly but in the network tab and response returned from handle the status will be reported as 200 which causes a bunch of weird side effects in your code when using things like
preloadData
.Reproduction
https://sveltelab.dev/f6fb6ey520ivhjy
Please notice that while the error page renders correctly with the right code, the hook reporting the status logs 200 and the network tab shows 200.
Logs
No response
System Info
Severity
serious, but I can work around it
Additional Information
No response
The text was updated successfully, but these errors were encountered: