From 0d8b50e5a21a91b035e1a45e94f0a40d571b3b4e Mon Sep 17 00:00:00 2001 From: Karol Wypchlo Date: Mon, 1 Mar 2021 17:19:13 +0100 Subject: [PATCH] better error handling --- setup-scripts/blocklist-airtable.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/setup-scripts/blocklist-airtable.py b/setup-scripts/blocklist-airtable.py index cf1872d8..b91ab3a8 100755 --- a/setup-scripts/blocklist-airtable.py +++ b/setup-scripts/blocklist-airtable.py @@ -15,8 +15,13 @@ async def block_skylinks_from_airtable(): headers = { "Authorization": "Bearer " + AIRTABLE_API_KEY } airtable = requests.get( "https://api.airtable.com/v0/" + AIRTABLE_TABLE + "/Table%201?fields%5B%5D=" + AIRTABLE_FIELD, headers=headers - ).json() - skylinks = [entry['fields'][AIRTABLE_FIELD] for entry in airtable['records']] + ) + + if airtable.status_code != 200: + message = "Airtable blocklist integration responded with code " + str(response.status_code) + ": " + (response.text or "empty response") + return print(message) and await send_msg(client, message, force_notify=False) + + skylinks = [entry['fields'][AIRTABLE_FIELD] for entry in airtable.json()['records']] print("Airtable returned " + str(len(skylinks)) + " skylinks to block") apipassword = os.popen('docker exec sia cat /sia-data/apipassword').read().strip() @@ -32,7 +37,7 @@ async def block_skylinks_from_airtable(): print("Skylinks successfully added to siad blocklist") else: message = "Siad blocklist endpoint responded with code " + str(response.status_code) + ": " + (response.text or "empty response") - await send_msg(client, message, force_notify=False) + await print(message) and send_msg(client, message, force_notify=False) async def exit_after(delay): await asyncio.sleep(delay)