express-openapi-validator icon indicating copy to clipboard operation
express-openapi-validator copied to clipboard

Fix #604: Send custom objects to middleware from security validators

Open rayvincent2 opened this issue 3 years ago • 0 comments

I was having the same issue where I wanted to send a custom error response format when encountering a 401 or 403 when validating tokens.

The solution that I went with was to create and export a CustomError class which people can instantiate and throw in their security handler callback functions. The handler simply needs to create an instance of the CustomError with a payload that will be passed to the next express middleware method.

I'll also need to update the documentation for the security validator usage to showcase how a custom object can be returned. https://github.com/cdimascio/express-openapi-validator/wiki/Documentation#security-handlers

See the test for an example of it's usage.

rayvincent2 avatar Aug 02 '22 04:08 rayvincent2