Handle errors from server

This commit is contained in:
Tony Garnock-Jones 2019-05-16 14:59:23 +01:00
parent fdf8a07a5d
commit 2f119b81af
2 changed files with 6 additions and 0 deletions

View File

@ -131,8 +131,13 @@ class Connection(object):
if protocol.Add.isClassOf(v): return self._lookup(v[0])._add(v[1])
if protocol.Del.isClassOf(v): return self._lookup(v[0])._del(v[1])
if protocol.Msg.isClassOf(v): return self._lookup(v[0])._msg(v[1])
if protocol.Err.isClassOf(v): return self._on_error(v[0])
if protocol.Ping.isClassOf(v): self._send(self._encode(protocol.Pong()))
def _on_error(self, detail):
log.error('%s: error from server: %r' % (self.__class__.__qualname__, detail))
self._disconnect()
def _send(self, bs):
raise Exception('subclassresponsibility')

View File

@ -14,6 +14,7 @@ Message = Record.makeConstructor('Message', 'body')
Add = Record.makeConstructor('Add', 'endpointName captures')
Del = Record.makeConstructor('Del', 'endpointName captures')
Msg = Record.makeConstructor('Msg', 'endpointName captures')
Err = Record.makeConstructor('Err', 'detail')
## Bidirectional
Ping = Record.makeConstructor('Ping', '')