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

Unpack error handler when registering on middleware #1695

Merged
merged 1 commit into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()