Skip to content

Commit

Permalink
handling erroneous dois
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Lopez committed Jul 13, 2020
1 parent 3417ca3 commit f42a807
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion richcontext/scholapi/scholapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,10 @@ def publication_lookup (self, identifier):

t0 = time.time()
url = self._get_api_url(identifier)
meta = json.loads(requests.get(url).text)
response = requests.get(url)
if response.status_code == requests.codes.ok:
meta = json.loads(response.text)

if not meta or len(meta) < 1 or "error" in meta:
meta = None
elif "message" in meta:
Expand Down
7 changes: 7 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,13 @@ def test_semantic_publication_lookup (self):
response = source.publication_lookup(doi)
self.assertTrue(response.meta == None)

# another error case
doi = "10.1641/0006-3568(2005)055[0879:EITLSA]2.0.CO;2"

if source.has_credentials():
response = source.publication_lookup(doi)
self.assertTrue(response.meta == None)


######################################################################
## Misc. family of APIs
Expand Down

0 comments on commit f42a807

Please sign in to comment.