Skip to content

feature: Add interface to override routing-controllers' default error handler #769

Open
@GeekEast

Description

@GeekEast

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

No one assigned

    Labels

    flag: needs discussionIssues which needs discussion before implementation.type: featureIssues related to new features.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions