From cbc802b7e9f5154d412a701bd027a3fec782ce0b Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Mon, 2 Nov 2020 00:17:22 +0000 Subject: [PATCH] Try Hackernews API twice --- apiserver/feeds/hackernews.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/apiserver/feeds/hackernews.py b/apiserver/feeds/hackernews.py index 4f400b7..5e951b0 100644 --- a/apiserver/feeds/hackernews.py +++ b/apiserver/feeds/hackernews.py @@ -25,6 +25,16 @@ def api(route, ref=None): return r.json() except KeyboardInterrupt: raise + except BaseException as e: + logging.error('Problem hitting hackernews API: {}, trying again'.format(str(e))) + + try: + r = requests.get(route(ref), timeout=15) + if r.status_code != 200: + raise Exception('Bad response code ' + str(r.status_code)) + return r.json() + except KeyboardInterrupt: + raise except BaseException as e: logging.error('Problem hitting hackernews API: {}'.format(str(e))) return False