Skip to content

Commit

Permalink
Log permission denied errors as such, instead of the full stack trace.
Browse files Browse the repository at this point in the history
Include which item IDs caused 500s.
  • Loading branch information
mihaip committed Jun 30, 2013
1 parent 29a92ff commit 0802a04
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
16 changes: 3 additions & 13 deletions base/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,19 +308,9 @@ def encode(s):
request_url = '%s?%s' % (url, urlencode(query_params))
url_fetcher = self._authenticated_url_fetcher if authenticated \
else self._direct_url_fetcher
try:
response_text = url_fetcher.fetch(
request_url,
post_data=urlencode(post_params) if post_params else None)
except urllib2.HTTPError, e:
if e.code >= 400 and e.code < 500:
# Log 400s, since they're usually programmer error, and the response
# indicates how to fix it.
logging.error(
'HTTP status %d when requesting %s. Error response body:\n%s',
e.code, request_url, e.read())
raise

response_text = url_fetcher.fetch(
request_url,
post_data=urlencode(post_params) if post_params else None)
if self._cache:
self._cache.set(cache_key, response_text)
return response_text
Expand Down
19 changes: 14 additions & 5 deletions reader_archive/reader_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,10 +362,18 @@ def work(self, stream_id):
result = []
continuation_token = None
while True:
item_refs, continuation_token = self._api.fetch_item_refs(
stream_id,
count=self._chunk_size,
continuation_token=continuation_token)
try:
item_refs, continuation_token = self._api.fetch_item_refs(
stream_id,
count=self._chunk_size,
continuation_token=continuation_token)
except urllib2.HTTPError, e:
if e.code == 400 and "Permission denied" in e.read():
logging.warn(" Permission denied when getting items for the stream "
"%s, it's most likely private now.", stream_id)
return None
else:
raise
result.extend(item_refs)
if not continuation_token or (self._max_items_per_stream and
len(result) >= self._max_items_per_stream):
Expand Down Expand Up @@ -419,7 +427,8 @@ def fetch(hifi=True):
'high-fidelity turned off')
return fetch(hifi=False)
except:
logging.error(' Exception when fetching items', exc_info=True)
logging.error(' Exception when fetching items %s',
",".join([i.compact_form() for i in item_ids]), exc_info=True)
return None

def _group_item_bodies(self, item_bodies):
Expand Down

0 comments on commit 0802a04

Please sign in to comment.