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

Schema validation errors not caught by error handler #1016

Closed
NMFR opened this issue Aug 13, 2019 · 3 comments
Closed

Schema validation errors not caught by error handler #1016

NMFR opened this issue Aug 13, 2019 · 3 comments

Comments

@NMFR
Copy link

NMFR commented Aug 13, 2019

Description

Schema validation errors are not caught by error handlers.
I want my application to have a "standard" JSON error format.
For this i register an error handler to format the error response.
Schema validation errors bypass the error handler and do not allow to format the response.

Expected behaviour

HTTP 500
{ "error": 'My custom error format" }

Actual behaviour

HTTP 400
{
  "detail": "1000 is greater than the maximum of 90",
  "status": 400,
  "title": "Validation error",
  "type": "about:blank"
}

Steps to reproduce

application.py:

connexion_app = connexion.App(root_path, specification_dir='src/api/rest')

def handle_connexion_exception(exception):
        return '{ "error": 'My custom error format" }', 500

connexion_app.add_error_handler(ProblemException, handle_connexion_exception)

Cause a openAPI schema error (call an endpoint with invalid JSON).

Additional info:

The culprit seems to be validate_schema https://github.com/zalando/connexion/blob/master/connexion/decorators/validation.py#L188 that does not throw an error and just returns the endpoint response.

NMFR added a commit to NMFR/connexion that referenced this issue Aug 13, 2019
This will allow users to intercept the error and format its response.
Also change the schema validation title to "Validation error" so the response is easier to read.

Fixes spec-first#1016
@TheBrunoLopes
Copy link

Any updates on this? This bug-fix would really come in handy.

@dtkav
Copy link
Collaborator

dtkav commented Nov 10, 2019

I think this is fixed by #955
Can you try the latest release?

@NMFR
Copy link
Author

NMFR commented Dec 9, 2019

Fixed

@NMFR NMFR closed this as completed Dec 9, 2019
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 a pull request may close this issue.

3 participants