Skip to content

Commit

Permalink
Move WebSocketConnectionError to exceptions (#1026) (#1124)
Browse files Browse the repository at this point in the history
  • Loading branch information
AdemOdza authored Oct 11, 2023
1 parent a9cca4f commit 37b5718
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion ariadne/asgi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from ..exceptions import WebSocketConnectionError
from ..types import (
Extensions,
MiddlewareList,
Expand All @@ -7,7 +8,6 @@
OnDisconnect,
OnOperation,
Operation,
WebSocketConnectionError,
)
from .graphql import GraphQL

Expand Down
2 changes: 1 addition & 1 deletion ariadne/asgi/handlers/graphql_ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
from starlette.types import Receive, Scope, Send
from starlette.websockets import WebSocket, WebSocketDisconnect, WebSocketState

from ...exceptions import WebSocketConnectionError
from ...graphql import parse_query, subscribe, validate_data
from ...logger import log_error
from ...types import (
Operation,
WebSocketConnectionError,
)
from ...utils import get_operation_type
from .base import GraphQLWebsocketHandler
Expand Down
12 changes: 12 additions & 0 deletions ariadne/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,15 @@ def format_message(self, file_path: Union[str, os.PathLike], message: str):
def __str__(self):
"""Returns error message."""
return self.message


class WebSocketConnectionError(Exception):
"""Special error class enabling custom error reporting for on_connect"""

def __init__(self, payload: Optional[Union[dict, str]] = None) -> None:
if isinstance(payload, dict):
self.payload = payload
elif payload:
self.payload = {"message": str(payload)}
else:
self.payload = {"message": "Unexpected error has occurred."}
13 changes: 0 additions & 13 deletions ariadne/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
"OnDisconnect",
"OnOperation",
"OnComplete",
"WebSocketConnectionError",
"Extension",
"SchemaBindable",
]
Expand Down Expand Up @@ -503,18 +502,6 @@ class Operation:
OnComplete = Callable[[WebSocket, Operation], Any]


class WebSocketConnectionError(Exception):
"""Special error class enabling custom error reporting for on_connect"""

def __init__(self, payload: Optional[Union[dict, str]] = None) -> None:
if isinstance(payload, dict):
self.payload = payload
elif payload:
self.payload = {"message": str(payload)}
else:
self.payload = {"message": "Unexpected error has occurred."}


class Extension:
"""Base class for extensions.
Expand Down
2 changes: 1 addition & 1 deletion tests/asgi/test_websockets_graphql_transport_ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from ariadne.asgi import GraphQL
from ariadne.asgi.handlers import GraphQLTransportWSHandler
from ariadne.types import WebSocketConnectionError
from ariadne.exceptions import WebSocketConnectionError
from ariadne.utils import get_operation_type


Expand Down
2 changes: 1 addition & 1 deletion tests/asgi/test_websockets_graphql_ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from ariadne.asgi import GraphQL
from ariadne.asgi.handlers import GraphQLWSHandler
from ariadne.types import WebSocketConnectionError
from ariadne.exceptions import WebSocketConnectionError


def test_field_can_be_subscribed_using_websocket_connection(client):
Expand Down

0 comments on commit 37b5718

Please sign in to comment.