hyper-express icon indicating copy to clipboard operation
hyper-express copied to clipboard

Could a router have a specific error handler ?

Open kapouer opened this issue 1 year ago • 3 comments

I understand that the (err, req, res, next) signature is not supported, however, that feature is really missing. For example, my app have three separate routers with totally different behaviors:

  • generates html pages
  • the api
  • static files

and each router needs to deal with errors very differently.

kapouer avatar Oct 10 '24 12:10 kapouer

Hello, as you may have read from previous issues and documentation, the hyper-express middleware system at the moment is very different from Express.js in both its operation and internal logic.

  • Middlewares and Routes are different without sharing the same signature.
  • Middlewares execute in a hierarchical manner where order is GLOBAL -> LOCAL -> ROUTE_SPECIFIC

Unfortunately, we only support a global error handler at the moment. I do think that a router specific error handler should be possible in theory since it would be an additive change rather than a breaking one.

Do you have reference on the signature, behavior and expectation of this feature?

kartikk221 avatar Oct 11 '24 04:10 kartikk221

A router-specific error handler would just have to get the error and be able to res.send() something.

Also while you are considering this, I think currently hyper-express doesn't catch errors when calling a middleware with (req, res, next) signature ?

kapouer avatar Oct 11 '24 07:10 kapouer

I am currently working on a router specific error handler. Would it be possible to be assigned to this?

zeta-squared avatar Dec 08 '24 11:12 zeta-squared