diff --git a/jupyter_server/gateway/connections.py b/jupyter_server/gateway/connections.py index 37d62d2f7..2bce86be8 100644 --- a/jupyter_server/gateway/connections.py +++ b/jupyter_server/gateway/connections.py @@ -146,9 +146,10 @@ def handle_outgoing_message(self, incoming_msg: str, *args: Any) -> None: def handle_incoming_message(self, message: str) -> None: """Send message to gateway server.""" if self.ws is None and self.ws_future is not None: - if self.ws_future.done() and isinstance(self.ws_future.exception(), Exception): - self.log.warning(f"Exception connect to websocket {self.ws_future.exception()}") - return + if self.ws_future.done() and self.ws_future.exception() is not None: + self.log.warning( + "Ignoring message on failed connection to kernel %s", self.kernel_id + ) loop = IOLoop.current() loop.add_future(self.ws_future, lambda future: self.handle_incoming_message(message)) else: