Skip to content

Commit

Permalink
Merge pull request #55 from seasidesparrow/api_fix_2023May11
Browse files Browse the repository at this point in the history
fix: catch missing esource fields in Holdings search
  • Loading branch information
seasidesparrow authored May 11, 2023
2 parents d523e43 + dbc2fdf commit 1c81367
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions journalsservice/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,24 @@ def get(self, bibstem, volume):
try:
q = ADSQuery()
solr_result = q.search(bibstem, volume)
data = solr_result['response']
count = data['numFound']
volume = data['docs'][0]['volume']
bibstem = data['docs'][0]['bibstem'][0]
holdings = [{'esources': rec['esources'], 'page': rec['page'][0]} for rec in data['docs']]
result = {'bibstem': bibstem,
'volume': volume,
'numFound': count,
'holdings': holdings}
data = solr_result.get('response', None)
if data:
count = data.get('numFound', 0)
docs = data.get('docs', [])
if docs:
volume = docs[0].get('volume', None)
bibstem = docs[0].get('bibstem', [])
if bibstem:
bibstem = bibstem[0]
holdings = [{'esources': rec.get('esources', None), 'page': rec.get('page', [None])[0]} for rec in docs]
result = {'bibstem': bibstem,
'volume': volume,
'numFound': count,
'holdings': holdings}
else:
result = {}
else:
result = {}
except Exception as err:
return {'Error': 'Holdings search failed',
'Error Info': str(err)}, 500
Expand Down

0 comments on commit 1c81367

Please sign in to comment.