Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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.

None yet

1 participant