Open
Description
Description
Currently routing-controllers' defaultErrorHandler is enabled by default.
If I want to do some error logging and error filtering using middleware, it can only happen after the error is sent to the client.
error filtering example
if (error instanceof JsonWebTokenError) return next(new UnauthorizedError(error.message))
I tried this approach
- turn off defaultErrorHandler
- write my own custom error handler middleware
But I got some issues:
- I cannot confirm that the error throw behavior is the same as before.
So I tried to replicate the default error handler, but I find it's quite complicated to override since it's not easy to get the actionMetadata object in middleware.
Proposed solution
I would suggest providing an interface like this to override the default error handler.
export class CustomErrorHandler {
handle(error:any, action: ActionMetadata | undefined, options: Action){
// developer can customer behaviours here.
}
}