From 654031e9b7141886e32c33c716ad97cd5a3b90a7 Mon Sep 17 00:00:00 2001 From: Anael Beutot Date: Tue, 22 May 2012 16:50:06 +0200 Subject: [PATCH] RPC error handling during auth. --- ccnode/node.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/ccnode/node.py b/ccnode/node.py index f4e3272..31c9a9d 100644 --- a/ccnode/node.py +++ b/ccnode/node.py @@ -7,7 +7,7 @@ from collections import defaultdict from functools import partial import pyev -from sjrpc.core import RpcConnection +from sjrpc.core import RpcConnection, RpcError from sjrpc.utils import ConnectionProxy, RpcHandler, threadless from ccnode import __version__ @@ -106,12 +106,21 @@ class RPCStartHandler(Thread): return # try to authenticate - self.auth_id = self.rpc_con.rpc.async_call_cb( - self.auth_done_cb, - 'authentify', - self.loop.config.server_user, - self.loop.config.server_passwd, - ) + try: + self.auth_id = self.rpc_con.rpc.async_call_cb( + self.auth_done_cb, + 'authentify', + self.loop.config.server_user, + self.loop.config.server_passwd, + ) + except RpcError as exc: + if exc.exception == 'RpcConnectionError': + logger.error('Authentication failed: connection lost') + else: + logger.exception('Unexpected exception while authenticating') + + self.stop() + self.loop.restart_rpc_connection() def auth_done_cb(self, call_id, response=None, error=None): assert call_id == self.auth_id -- GitLab