seanpmaxwell/overnight

Add ErrorRequestHandler as an acceptable type for @Middleware decorator

Closed this issue · 6 comments

Currently the @Middleware decorator accepts only express's core.RequestHandler, but I have the need to add a middleware for handling errors throwed by the controller which implements core.ErrorRequestHandler as explained here: https://expressjs.com/en/guide/error-handling.html

Sorry I haven't tended to this. Is there any chance you could create a pull request for this? I've been so busy with some other stuff lately. The only middleware I've ever used is RequestHandler so that's all I'm familiar with.

sweko commented

I can take this up, as I have it functional (via an inline hack inside node_modules).
However, since error middleware (in contrast to regular middleware) has to be registered after the routes have been registered, I think it would be best to create two additional decorators (ErrorMiddleware and ClassErrorMiddleware) to handle that, and avoid mixing up the two concepts. Is that ok?

Yeah that's fine, go for it. If it's not too much extra work, mind updating the README too. That would be helpful.

sweko commented

Have it working, I'm updating the samples now

@sweko could you create a pull request with your changes

published changes in @sweko 's pull request to npm so closing this issue. Thanks @sweko for all your hard work!