Hi, my site (flannelfy.net) has recently started resulting in a 502-backend error somewhat frequently. However, I cannot reliably replicate the error; sometimes it will happen on my first attempt at using the site and sometimes I'll have to try multiple times before getting the error. My site uses the Spotify and Last.fm APIs, and the error can occur in either one; refreshing, as the error page suggests, sometimes (but not always) fixes the issue. I thought it might be an issue with expiring API tokens, which may still be partially the case with the Spotify functionality, but Last.fm doesn't rely on tokens that can expire and the same problem arises.
I've made sure to try it while the site wasn't in the process of reloading, and my error log unfortunately stopped updating a few hours ago as of writing this; the only suspicious message in my server log is: "corrupted size vs. prev_size", which seems to be something I have no direct influence over, though I'm not certain.
A link to the sourse code is given at the bottom of my home page and I'm happy to provide any additional information; any help is greatly appreciated. At the very least, I would like to be able to catch the error and exit gracefully with a custom error page, but I can't reliably find the source of the issue.