Skip to content
Snippets Groups Projects
Commit ac89f2fa authored by Antoine Millet's avatar Antoine Millet
Browse files

Reworked exception tree.

RpcError are now reserved to rpc protocol, the RpcConnection uses the new
RpcConnectionError class.
parent 05136a3b
No related branches found
No related tags found
No related merge requests found
......@@ -18,17 +18,17 @@ class RpcError(Exception):
return '%s' % self.message
class SocketRpcError(Exception):
class RpcConnectionError(Exception):
'''
Exception used internally to raise a socket fault.
Base class for RpcConnection errors.
'''
class RpcConnectionError(Exception):
class SocketError(RpcConnectionError):
'''
Base class for RpcConnection errors.
Exception used internally to raise a socket fault.
'''
......
......@@ -5,7 +5,7 @@ from uuid import uuid4
from threading import Event, Thread
from sjrpc.core.exceptions import RpcError
from sjrpc.core.exceptions import RpcError, RpcConnectionError
from sjrpc.core.protocols import Protocol
__all__ = ['RpcProtocol']
......@@ -208,12 +208,12 @@ class RpcProtocol(Protocol):
Message must be a jsonisable structure.
'''
#if not self._connected: #FIXME
# raise RpcError('SendError', 'disconnected from the peer')
self.logger.debug('Sending: %s', message)
json_msg = json.dumps(message)
self._connection.send(self._label, payload=json_msg)
try:
self._connection.send(self._label, payload=json_msg)
except RpcConnectionError as err:
raise RpcError('RpcConnectionError', str(err))
def _send_call(self, method_name, *args, **kwargs):
'''
......
......@@ -14,8 +14,8 @@ import logging
import threading
from sjrpc.core.protocols import Protocol, RpcProtocol, TunnelProtocol
from sjrpc.core.exceptions import (RpcError, NoFreeLabelError,
FallbackModeEnabledError)
from sjrpc.core.exceptions import (RpcConnectionError, NoFreeLabelError,
FallbackModeEnabledError, SocketError)
import pyev
......@@ -293,7 +293,7 @@ class RpcConnection(object):
except socket.error as err:
errmsg = 'Fatal error while sending through socket: %s' % err
self.logger.error(errmsg)
raise RpcError('SocketError', errmsg)
raise SocketError(errmsg)
self._outbound_buffer = self._outbound_buffer[sent:]
if not self._outbound_buffer:
......@@ -334,7 +334,7 @@ class RpcConnection(object):
'''
self._event_fallback.wait()
if not self._connected:
raise RpcError('RpcError', 'Not connected to the peer')
raise RpcConnectionError('Not connected to the peer')
size = len(payload)
if self.fallback:
header = struct.pack(RpcConnection.MESSAGE_HEADER_FALLBACK, size)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment