From a48fcb096e19cff0ac5488de51c824aa66c4416f Mon Sep 17 00:00:00 2001 From: Michael Thomas Date: Tue, 7 Mar 2023 06:59:06 +0000 Subject: [PATCH] add some error handling in json parsing --- get_context.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/get_context.py b/get_context.py index b215fb4..ce15502 100644 --- a/get_context.py +++ b/get_context.py @@ -300,9 +300,13 @@ def get_toot_context(server, toot_id, toot_url): return [] if resp.status_code == 200: - res = resp.json() - print(f"Got context for toot {toot_url}") - return (toot["url"] for toot in (res["ancestors"] + res["descendants"])) + try: + res = resp.json() + print(f"Got context for toot {toot_url}") + return (toot["url"] for toot in (res["ancestors"] + res["descendants"])) + except Exception as ex: + print(f"Error parsing context for toot {toot_url}. Exception: {ex}") + return [] print( f"Error getting context for toot {toot_url}. Status code: {resp.status_code}"