-
Notifications
You must be signed in to change notification settings - Fork 399
Open
Labels
flag: needs discussionIssues which needs discussion before implementation.Issues which needs discussion before implementation.type: featureIssues related to new features.Issues related to new features.
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.
}
}
Metadata
Metadata
Assignees
Labels
flag: needs discussionIssues which needs discussion before implementation.Issues which needs discussion before implementation.type: featureIssues related to new features.Issues related to new features.