From 6a5c6dd7888847df73c07e0d9ff204b079dadd37 Mon Sep 17 00:00:00 2001 From: Ben Morrice <ben.morrice@cern.ch> Date: Thu, 12 Oct 2023 10:23:42 +0200 Subject: [PATCH] Capture json.loads exceptions --- package_alerts/package_alerts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/package_alerts/package_alerts b/package_alerts/package_alerts index 3210e40..7dc8e37 100755 --- a/package_alerts/package_alerts +++ b/package_alerts/package_alerts @@ -115,7 +115,11 @@ def get_token(ot): if result.status_code != 200: print("unable to auth, exiting") sys.exit(1) - token = json.loads(result.content)["access_token"] + try: + token = json.loads(result.content)["access_token"] + except json.decoder.JSONDecodeError: + print("unable to auth, exiting") + sys.exit(1) return token @@ -136,7 +140,12 @@ def get_upstream(token, feed): packages = [] while True: result = call_api(token, url, params={"limit": 100, "offset": offset}) - j = json.loads(result.content) + try: + j = json.loads(result.content) + except json.decoder.JSONDecodeError: + # TODO: fix this? + print("Encountered an error retrieving upstream packages, exiting loop", flush=True) + return [] offset = j["pagination"]["offset"] count = j["pagination"]["count"] for p in j["body"]: -- GitLab