From b78b3fe215af482828434a41d771e7b84de8801e Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Thu, 1 May 2014 23:00:07 +0200 Subject: more verbose error messages --- bin/updater.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/bin/updater.py b/bin/updater.py index 5eb8eded8..2942d9a2b 100644 --- a/bin/updater.py +++ b/bin/updater.py @@ -19,6 +19,11 @@ import threading import requests import urllib +def check_status_code(response): + if response.status_code != 200: + raise Exception('Request failed with %i: %s' % (response.status_code, + response.text)) + class UpdateThread(threading.Thread): lock = threading.Lock() @@ -52,7 +57,8 @@ class UpdateThread(threading.Thread): try: auth = (self.user, self.password) - requests.get(url, auth=auth, timeout=self.timeout) + request = requests.get(url, auth=auth, timeout=self.timeout) + check_status_code(request) except (Exception) as e: print('%s: %s' % (url, e)) @@ -86,9 +92,12 @@ class Updater: # run the cleanup request and get all the feeds to update auth = (self.user, self.password) - requests.get(self.before_cleanup_url, auth=auth) + before = requests.get(self.before_cleanup_url, auth=auth) + check_status_code(before) feeds_response = requests.get(self.all_feeds_url, auth=auth) + check_status_code(feeds_response) + feeds_json = feeds_response.text feeds = json.loads(feeds_json)['feeds'] @@ -103,7 +112,8 @@ class Updater: for thread in threads: thread.join() - requests.get(self.after_cleanup_url, auth=auth) + after = requests.get(self.after_cleanup_url, auth=auth) + check_status_code(after) if self.run_once: return -- cgit v1.2.3