Improve try/except logic in __do_gracedb_alert
As outlined by @andrewmichael.gozzard during internal review for !53 (merged), there is a lot of try/except clauses when handling whether or not a GraceDb upload is successful or not. Best practice try/except
should specify what types of exception it is intended to catch, as wildcard catch can cause unexpected behaviour, particularly in the case of unrecoverable errors.
We would recommend creating a new branch in Python3 that uses the latest version of ligo.gracedb (and therefore the latest version of whatever HTTPErrors or exception libraries it might use, etc) and structure a try/except/else block something like:
for _ in range(gracedb_upload_attempts):
try:
# upload coinc.xml to gracedb
resp = gracedb.create_event()
# manually raise exception if 201 is not returned
# although, ligo.gracedb.rest may already raise an exception
if resp.status_code != 201:
raise HTTPError() # or appropriate exception
except HTTPError as exc:
logger.info(f"Exception raised: {exc}")
else:
# if no exception was raised then
response_json = resp.json()
gracedb_id = response_json["grace_id"]
logger.info("gracedb_id {gracedb_id} uploaded succeeeded!")