-
-
Notifications
You must be signed in to change notification settings - Fork 946
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(WebSocket): properly handle HTTPStatus and HTTPError cases (#2150)
* fix(websocket): properly handle HTTPStatus and HTTPError cases when using websockets * test: fix failing tests * test: add missing test coverage * docs: add newsfragment * chore: explicit raise for unsupported call of internal methods * style: fix imports * docs(towncrier): improve the bugfix newsfragment --------- Co-authored-by: Vytautas Liuolia <[email protected]>
- Loading branch information
Showing
7 changed files
with
212 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
:ref:`WebSocket <ws>` implementation has been fixed to properly handle | ||
:class:`~falcon.HTTPError` and :class:`~falcon.HTTPStatus` exceptions raised by | ||
custom :func:`error handlers <falcon.asgi.App.add_error_handler>`. | ||
The WebSocket connection is now correctly closed with an appropriate code | ||
instead of bubbling up an unhandled error to the application server. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# misc test for 100% coverage | ||
|
||
from unittest.mock import MagicMock | ||
|
||
import pytest | ||
|
||
from falcon.asgi import App | ||
from falcon.http_error import HTTPError | ||
from falcon.http_status import HTTPStatus | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_http_status_not_impl(): | ||
app = App() | ||
with pytest.raises(NotImplementedError): | ||
await app._http_status_handler(MagicMock(), None, HTTPStatus(200), {}, None) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_http_error_not_impl(): | ||
app = App() | ||
with pytest.raises(NotImplementedError): | ||
await app._http_error_handler(MagicMock(), None, HTTPError(400), {}, None) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_python_error_not_impl(): | ||
app = App() | ||
with pytest.raises(NotImplementedError): | ||
await app._python_error_handler( | ||
MagicMock(), None, ValueError('error'), {}, None | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters