diff options
Diffstat (limited to 'diplomacy/server/connection_handler.py')
-rw-r--r-- | diplomacy/server/connection_handler.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/diplomacy/server/connection_handler.py b/diplomacy/server/connection_handler.py index a70db7d..2b2ae4d 100644 --- a/diplomacy/server/connection_handler.py +++ b/diplomacy/server/connection_handler.py @@ -33,6 +33,7 @@ LOGGER = logging.getLogger(__name__) class ConnectionHandler(WebSocketHandler): """ ConnectionHandler class. Properties: + - server: server object representing running server. """ # pylint: disable=abstract-method @@ -43,6 +44,7 @@ class ConnectionHandler(WebSocketHandler): def initialize(self, server=None): """ Initialize the connection handler. + :param server: a Server object. :type server: diplomacy.Server """ @@ -69,6 +71,7 @@ class ConnectionHandler(WebSocketHandler): parsed_origin = urlparse(origin) origin = parsed_origin.netloc.split(':')[0] origin = origin.lower() + # Split host with ':' and keep only first piece to ignore eventual port. host = self.request.headers.get("Host").split(':')[0] return origin == host @@ -89,6 +92,7 @@ class ConnectionHandler(WebSocketHandler): @staticmethod def translate_notification(notification): """ Translate a notification to an array of notifications. + :param notification: a notification object to pass to handler function. See diplomacy.communication.notifications for possible notifications. :return: An array of notifications containing a single notification. @@ -103,8 +107,10 @@ class ConnectionHandler(WebSocketHandler): if not isinstance(json_request, dict): raise ValueError("Unable to convert a JSON string to a dictionary.") except ValueError as exc: - # Error occurred because either message is not a JSON string or parsed JSON object is not a dict. - response = responses.Error(message='%s/%s' % (type(exc).__name__, str(exc))) + # Error occurred because either message is not a JSON string + # or parsed JSON object is not a dict. + response = responses.Error(error_type=exceptions.ResponseException.__name__, + message=str(exc)) else: try: request = requests.parse_dict(json_request) @@ -118,7 +124,8 @@ class ConnectionHandler(WebSocketHandler): response = responses.Ok(request_id=request.request_id) except exceptions.ResponseException as exc: - response = responses.Error(message='%s/%s' % (type(exc).__name__, exc.message), + response = responses.Error(error_type=type(exc).__name__, + message=exc.message, request_id=json_request.get(strings.REQUEST_ID, None)) if response: |