Skip to content
This repository has been archived by the owner on Jul 6, 2020. It is now read-only.

Commit

Permalink
more verbose error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernhard Posselt committed May 1, 2014
1 parent 94b3fc7 commit b78b3fe
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions bin/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
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()
Expand Down Expand Up @@ -52,7 +57,8 @@ def run(self):

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))

Expand Down Expand Up @@ -86,9 +92,12 @@ def run(self):
# 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']

Expand All @@ -103,7 +112,8 @@ def run(self):
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
Expand Down

0 comments on commit b78b3fe

Please sign in to comment.