Re:Ask HN: Is Express still "de-facto" for building Node bac...
by contextnavidad on Sunday October 29, 2023 @11:31AM
(#38059500)
> async middleware not handling errors properly thing though
Can you expand on this? Error handling in middleware is pretty well documented.
Re:Ask HN: Is Express still "de-facto" for building Node bac...
by roblh on Sunday October 29, 2023 @12:14PM
(#38059956)
Anytime an error happens inside an async middleware in express, you have to explicitly catch it and pass it directly to the `next` function, otherwise it'll just disappear and any kind of error logging middleware you have later on will never see it. In synchronous functions any error is passed automatically. You can write more middleware to address this, or just manually catch everything, but it just means more boilerplate. There's no reason to expect different types of middleware to have different behaviour unless you already know. It's not catastrophic, but I expect more consistent design from such an established library, especially considering how long this has been an issue.
I guess there’s Bun and Elysia now too, but that’s pretty bleeding edge by comparison.