Potential internal CF Pages issue: Error 500 on first post request but not subsequent ones

The pages worker seems to fail to process the first post request, but a try catch on the entire backend doesn't catch it and it happens even if there is no backend code other than just returning OK directly. I suspect that there is an issue at Cloudlfare Pages, SvelteKit or the Cloudflare Pages Adapter for SvelteKit. The Error 500: Unexpected token '<', "<!DOCTYPE "... is not valid JSON or JSON.parse: unexpected character at line 1 column 1 of the JSON data
2 Replies
2fun
2funOP3mo ago
Is there a way to get the stacktrace to know exactly where it happens? This doesn't happen running the page locally using the node adapter for SvelteKit or using the wrangler pages dev command Therefore I strongly think it is a Cloudflare Pages internal issue Fixed the issue with this code:
import { browser } from '$app/environment';

if (browser) {
let loaded = sessionStorage.getItem('form_page_reload');
if (!loaded) { // Fixes weird Cloudflare Pages "Error 500 on initial post" issue
sessionStorage.setItem('form_page_reload', 'true');
location.reload();
}
}
import { browser } from '$app/environment';

if (browser) {
let loaded = sessionStorage.getItem('form_page_reload');
if (!loaded) { // Fixes weird Cloudflare Pages "Error 500 on initial post" issue
sessionStorage.setItem('form_page_reload', 'true');
location.reload();
}
}
It just refreshes the page once to "skip" the initial phase I guess. Weird After some debugging, I found in the wrangler logs that there is no GET request initially. So instead of using svelte's goto(url) function I just did window.location.href = url instead Seems to have fixed it
Matix
Matix3mo ago
hi @2fun im experiencing a similar issue. How did you access the wranger logs? Nvm, I think I figured out.. But the logs are not really helpful aswell
Want results from more Discord servers?
Add your server