API: Amend call_on_each_event error handling to not use .get().

mypy with strict-optional led to examination of res.get('result')
calls potentially raising TypeError ('error' in None).

Server code indicates this is safe, and other nearby code assumes
presence of fields in 'res' also.
This commit is contained in:
neiljp (Neil Pilgrim) 2018-01-07 04:26:25 -08:00 committed by showell
parent 1de704394a
commit 2a2c8ae25f

View file

@ -588,7 +588,7 @@ class Client(object):
else: else:
res = self.register(event_types=event_types, narrow=narrow) res = self.register(event_types=event_types, narrow=narrow)
if 'error' in res.get('result'): if 'error' in res['result']:
if self.verbose: if self.verbose:
print("Server returned error:\n%s" % res['msg']) print("Server returned error:\n%s" % res['msg'])
time.sleep(1) time.sleep(1)
@ -604,7 +604,7 @@ class Client(object):
(queue_id, last_event_id) = do_register() (queue_id, last_event_id) = do_register()
res = self.get_events(queue_id=queue_id, last_event_id=last_event_id) res = self.get_events(queue_id=queue_id, last_event_id=last_event_id)
if 'error' in res.get('result'): if 'error' in res['result']:
if res["result"] == "http-error": if res["result"] == "http-error":
if self.verbose: if self.verbose:
print("HTTP error fetching events -- probably a server restart") print("HTTP error fetching events -- probably a server restart")