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

Exception handling in aiohttp #898

Closed
SpudInNZ opened this issue Mar 6, 2019 · 4 comments
Closed

Exception handling in aiohttp #898

SpudInNZ opened this issue Mar 6, 2019 · 4 comments

Comments

@SpudInNZ
Copy link

SpudInNZ commented Mar 6, 2019

Description

I am trying to figure out how to add an exception handling method to Connexion when using the aiohttp web server. The docs at https://connexion.readthedocs.io/en/latest/exceptions.html#default-exception-handling talk of add_error_handler, but it seems this is only available for Flask?

Expected behaviour

I expect that ProblemExceptions raised by request validation can be handled by the server, so a 400 error can be returned to the client when an incorrectly formatted HTTP request is received for example.

Actual behaviour

ProblemExceptions raised are not handled, and therefore a 500 error is returned to the client when a badly formatted HTTP request is made.

Steps to reproduce

  1. Define GET request in Swagger spec, for example GET /accounts
  2. Enable request validation in server startup, e.g.
cnx_app.add_api('swagger.yaml',
                    pass_context_arg_name="request",
                    validate_responses=True,
                   strict_validation=True)
  1. Make request with unexpected parameter, e.g. GET /accounts?someUnexpectedArg=1
  2. Server returns 500 error, as no exception handler is installed that can catch the ProblemException that gets raised.

Additional info:

Python version 3.7.1
Connexion version 2.0.2

@SpudInNZ
Copy link
Author

Any thoughts on this @dtkav ?

@dtkav
Copy link
Collaborator

dtkav commented Mar 26, 2019 via email

@cognifloyd
Copy link
Contributor

In order to add error handling in aiohttp, you need to add a middleware that catches the exception.

Related: #952, #955

In both of these PRs, a middleware handles problem exceptions.
In #952, all exceptions are turned into Problems.

@cognifloyd
Copy link
Contributor

Both #952 and #955 have been merged. @SpudInNZ can you try a newer release and see if that resolves your issue?

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

No branches or pull requests

4 participants