Skip to content

Commit

Permalink
Catching missing pubmed so it's not a 500
Browse files Browse the repository at this point in the history
  • Loading branch information
wshayes committed Mar 27, 2018
1 parent 4f762fa commit a57cb17
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions bel/nanopub/pubmed.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,11 @@ def get_pubmed(pmid: str) -> Mapping[str, Any]:
Returns:
pubmed json
"""
r = get_url(PUBMED_TMPL.replace('PMID', pmid))
pubmed_url = PUBMED_TMPL.replace('PMID', pmid)
r = get_url(pubmed_url)
log.info(f'Getting Pubmed URL {pubmed_url}')

if r.status_code == 200:
try:
root = etree.fromstring(r.content)
doc = {}
doc['pmid'] = root.xpath("//PMID/text()")[0]
Expand Down Expand Up @@ -159,9 +161,9 @@ def get_pubmed(pmid: str) -> Mapping[str, Any]:
doc['mesh'].append({'id': mesh_id, 'name': mesh.text})

return doc
else:
except Exception as e:
log.error(f"Bad Pubmed request, status: {r.status_code} url: {PUBMED_TMPL.replace('PMID', pmid)}")
return {}
return {'message': f"Cannot get PMID: {pubmed_url}"}


def enhance_pubmed_annotations(pubmed: Mapping[str, Any]) -> Mapping[str, Any]:
Expand Down

0 comments on commit a57cb17

Please sign in to comment.