Debug Errors in Pages

Some of the time my Pages site will throw a “500 Internal Error” without any real hint as to why. When refreshing a few seconds later it will work fine. I’m sure this is some function that isn’t running correctly, but I can’t recreate it locally.

How can I debug this issue? Is there a log somewhere? (The functions log of the site says everything went well.) Or is there a way in which I can locally run a pages server?

wrangler pages dev <folder>

Install wrangler in your project, or systemwide, with npm.