Skip to content

Commit

Permalink
Unpack error handler when registering on middleware (#1695)
Browse files Browse the repository at this point in the history
Registering error handlers on the async app leads to an error on 3.0.0a5
because the error handlers are not unpacked correctly when being
registered internally.
  • Loading branch information
RobbeSneyders committed Apr 24, 2023
1 parent 97e8a8e commit c3e2e57
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion connexion/middleware/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def _build_middleware_stack(self) -> t.Tuple[ASGIApp, t.Iterable[ASGIApp]]:

if isinstance(app, ExceptionMiddleware):
for error_handler in self.error_handlers:
app.add_exception_handler(error_handler)
app.add_exception_handler(*error_handler)

return app, list(reversed(apps))

Expand Down
13 changes: 13 additions & 0 deletions tests/api/test_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,3 +295,16 @@ def test_async_route(simple_app):
app_client = simple_app.test_client()
resp = app_client.get("/v1.0/async-route")
assert resp.status_code == 200


def test_add_error_handler(app_class, simple_api_spec_dir):
app = app_class(__name__, specification_dir=simple_api_spec_dir)
app.add_api("openapi.yaml")

def custom_error_handler(_request, _exception):
pass

app.add_error_handler(Exception, custom_error_handler)
app.add_error_handler(500, custom_error_handler)

app.middleware._build_middleware_stack()

0 comments on commit c3e2e57

Please sign in to comment.