diff options
Diffstat (limited to 'venv/lib/python3.11/site-packages/litestar/exceptions/websocket_exceptions.py')
-rw-r--r-- | venv/lib/python3.11/site-packages/litestar/exceptions/websocket_exceptions.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/venv/lib/python3.11/site-packages/litestar/exceptions/websocket_exceptions.py b/venv/lib/python3.11/site-packages/litestar/exceptions/websocket_exceptions.py new file mode 100644 index 0000000..2fed9ca --- /dev/null +++ b/venv/lib/python3.11/site-packages/litestar/exceptions/websocket_exceptions.py @@ -0,0 +1,40 @@ +from typing import Any + +from litestar.exceptions.base_exceptions import LitestarException +from litestar.status_codes import WS_1000_NORMAL_CLOSURE + +__all__ = ("WebSocketDisconnect", "WebSocketException") + + +class WebSocketException(LitestarException): + """Exception class for websocket related events.""" + + code: int + """Exception code. For custom exceptions, this should be a number in the 4000+ range. Other codes can be found in + ``litestar.status_code`` with the ``WS_`` prefix. + """ + + def __init__(self, *args: Any, detail: str, code: int = 4500) -> None: + """Initialize ``WebSocketException``. + + Args: + *args: Any exception args. + detail: Exception details. + code: Exception code. Should be a number in the >= 1000. + """ + super().__init__(*args, detail=detail) + self.code = code + + +class WebSocketDisconnect(WebSocketException): + """Exception class for websocket disconnect events.""" + + def __init__(self, *args: Any, detail: str, code: int = WS_1000_NORMAL_CLOSURE) -> None: + """Initialize ``WebSocketDisconnect``. + + Args: + *args: Any exception args. + detail: Exception details. + code: Exception code. Should be a number in the >= 1000. + """ + super().__init__(*args, detail=detail, code=code) |