Worker with async Promises throws “This script will never generate a response.”

Hi, I have the following script hosted on a worker. When I send a HTTP POST request to /api/log with entries to log, I get an error from Cloudflare that the script will never generate a response. I am using a KV namespace for the worker code. The idea is to be able to write logs that I can use to communicate between platforms.
2 Replies
sumerokr
sumerokr15mo ago
check your switch/case block you don't have default branch. If (theoretically) none of your cases match, then there is no Response returned
Guidelines
GuidelinesOP15mo ago
There shouldn’t be any switch case in the if-statement I’m hitting. I know that if I have a payload with 0 objects in the array then the code responds fine. If I hit the /api/userloads endpoint then that also works fine. So I’m narrowing it down to do with the Promises somehow not resolving. But I’m unsure if I can debug this with some breakpoints locally (though it likely might be possible) blobhajSolution The code within the Promise was failing. const userLogsStr = (await env.FF_EVENTLOG.get('log_' + _userId + '_' + pageIndex, 'text')) || ''; That line would firstly result in en empty string, which couldn't be parsed and cast to the type UserLogs which is an array-type. Because of this the code erroneously(?) errored that a response couldn't ever be generated 🙂 Changing '' to '[]' fixes the problem.
Want results from more Discord servers?
Add your server