Skip to content

Conversation

rayvincent2
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant