protect against errors from the hound API

When codesearch.o.o is re-indexing the API responds with something
that is not JSON. Rather than worry about all of the various errors we
could receive from an API that is only providing advisory information,
catch anything, log it, and proceed in a safe manner.

Change-Id: Ia910215029b3ece31db180396dbb50c82a7f3a59
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
Doug Hellmann 2018-06-14 13:23:50 -04:00
parent 3c9b15af15
commit a0c983e0b8

View File

@ -16,9 +16,12 @@
"""
import logging
import requests
LOG = logging.getLogger(__name__)
_URL = 'http://codesearch.openstack.org/api/v1/search'
@ -39,14 +42,19 @@ def _query(q, **kwds):
def get_dependency_listings(package_name):
return _query(
q=package_name,
# NOTE(dhellmann): Including setup.cfg shows *lots* of results
# for oslo.config because of the plugins for the config
# generator. It would be nice to figure out how to filter
# those.
files='(.*requirements.txt|.*constraint.*.txt)',
)
try:
return _query(
q=package_name,
# NOTE(dhellmann): Including setup.cfg shows *lots* of results
# for oslo.config because of the plugins for the config
# generator. It would be nice to figure out how to filter
# those.
files='(.*requirements.txt|.*constraint.*.txt)',
)
except Exception as e:
LOG.error('Could not fetch users of %s: %s',
package_name, e)
return {}
def show_dependency_listings(package_name, official_repos):