mirror of
https://github.com/zulip/zulip.git
synced 2025-11-13 10:26:28 +00:00
Wrap most of fetch_events in a try/except JsonableError.
This is a no-op right now, but we'll want the new structure for the next commit, and splitting this out makes it a lot easier to read what is actually changed in the next commit.
This commit is contained in:
@@ -447,40 +447,44 @@ def fetch_events(query):
|
|||||||
client_type_name = query["client_type_name"]
|
client_type_name = query["client_type_name"]
|
||||||
handler_id = query["handler_id"]
|
handler_id = query["handler_id"]
|
||||||
|
|
||||||
was_connected = False
|
try:
|
||||||
orig_queue_id = queue_id
|
was_connected = False
|
||||||
extra_log_data = ""
|
orig_queue_id = queue_id
|
||||||
if queue_id is None:
|
extra_log_data = ""
|
||||||
if dont_block:
|
if queue_id is None:
|
||||||
client = allocate_client_descriptor(new_queue_data)
|
if dont_block:
|
||||||
queue_id = client.event_queue.id
|
client = allocate_client_descriptor(new_queue_data)
|
||||||
|
queue_id = client.event_queue.id
|
||||||
|
else:
|
||||||
|
raise JsonableError("Missing 'queue_id' argument")
|
||||||
else:
|
else:
|
||||||
raise JsonableError("Missing 'queue_id' argument")
|
if last_event_id is None:
|
||||||
else:
|
raise JsonableError("Missing 'last_event_id' argument")
|
||||||
if last_event_id is None:
|
client = get_client_descriptor(queue_id)
|
||||||
raise JsonableError("Missing 'last_event_id' argument")
|
if client is None:
|
||||||
client = get_client_descriptor(queue_id)
|
raise JsonableError("Bad event queue id: %s" % (queue_id,))
|
||||||
if client is None:
|
if user_profile_id != client.user_profile_id:
|
||||||
raise JsonableError("Bad event queue id: %s" % (queue_id,))
|
raise JsonableError("You are not authorized to get events from this queue")
|
||||||
if user_profile_id != client.user_profile_id:
|
client.event_queue.prune(last_event_id)
|
||||||
raise JsonableError("You are not authorized to get events from this queue")
|
was_connected = client.finish_current_handler()
|
||||||
client.event_queue.prune(last_event_id)
|
|
||||||
was_connected = client.finish_current_handler()
|
|
||||||
|
|
||||||
if not client.event_queue.empty() or dont_block:
|
if not client.event_queue.empty() or dont_block:
|
||||||
ret = {'events': client.event_queue.contents()}
|
ret = {'events': client.event_queue.contents()}
|
||||||
if orig_queue_id is None:
|
if orig_queue_id is None:
|
||||||
ret['queue_id'] = queue_id
|
ret['queue_id'] = queue_id
|
||||||
extra_log_data = "[%s/%s]" % (queue_id, len(ret["events"]))
|
extra_log_data = "[%s/%s]" % (queue_id, len(ret["events"]))
|
||||||
|
if was_connected:
|
||||||
|
extra_log_data += " [was connected]"
|
||||||
|
return (ret, extra_log_data)
|
||||||
|
|
||||||
|
# After this point, dont_block=False, the queue is empty, and we
|
||||||
|
# have a pre-existing queue, so we wait for new events.
|
||||||
if was_connected:
|
if was_connected:
|
||||||
extra_log_data += " [was connected]"
|
logging.info("Disconnected handler for queue %s (%s/%s)" % (queue_id, user_profile_email,
|
||||||
return (ret, extra_log_data)
|
client_type_name))
|
||||||
|
except JsonableError as e:
|
||||||
|
raise e
|
||||||
|
|
||||||
# After this point, dont_block=False, the queue is empty, and we
|
|
||||||
# have a pre-existing queue, so we wait for new events.
|
|
||||||
if was_connected:
|
|
||||||
logging.info("Disconnected handler for queue %s (%s/%s)" % (queue_id, user_profile_email,
|
|
||||||
client_type_name))
|
|
||||||
client.connect_handler(handler_id, client_type_name)
|
client.connect_handler(handler_id, client_type_name)
|
||||||
return (RespondAsynchronously, None)
|
return (RespondAsynchronously, None)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user