This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Uncaught error in async endpoint crashes express #2337
Labels
status: needs-triage
Possible bug which hasn't been reproduced yet
Bug Report
Any uncaught errors in an async
handler
function of an endpoint will crash the underlying express instance (however not the process as it seems). I understand that this is something that is flawed in express and should be fixed upstream however the Payload docs themselves use an async endpoint in the docs without any mention of this issue so I feel like it should be handled until express 5 becomes stable.Workaround in the form of a plugin is included below.
Steps to Reproduce
Other Details
After some digging, it turns out that Express 4 does not handle errors in async route handlers which will be fixed in Express 5 however that's been in beta for a year now (related issue with maintainer updates: expressjs/express#4920).
My two ideas for resolution of this would be:
And then using that function in here (maybe somewhere else, I haven't looked far and wide but this seemed like a reasonable guess):
payload/src/express/mountEndpoints.ts
Lines 4 to 12 in 4d578f1
Payload version: 1.6.17
Workaround (Payload plugin)
Using the function from above, it's possible to write a plugin as workaround that handles async errors gracefully:
The text was updated successfully, but these errors were encountered: