diff --git a/src/mavedb/lib/external_publications.py b/src/mavedb/lib/external_publications.py index a48ff718..96c4f8dd 100644 --- a/src/mavedb/lib/external_publications.py +++ b/src/mavedb/lib/external_publications.py @@ -564,4 +564,13 @@ def _fetch(self, url: str, return_format: str = "json") -> Any: return [] response.raise_for_status() - return json.loads(response.text) if return_format == "json" else response.text + + if return_format == "json": + if not response.text or not response.text.strip(): + return [] + try: + return json.loads(response.text) + except json.JSONDecodeError: + return [] + + return response.text diff --git a/src/mavedb/lib/identifiers.py b/src/mavedb/lib/identifiers.py index d5bfdbd4..893442af 100644 --- a/src/mavedb/lib/identifiers.py +++ b/src/mavedb/lib/identifiers.py @@ -216,7 +216,10 @@ async def fetch_biorxiv_article(identifier: str) -> Optional[RxivContentDetail]: Fetch an existing bioRxiv article from Rxiv """ fetch = Rxiv("https://api.biorxiv.org", "biorxiv") - articles = fetch.content_detail(identifier=identifier) + try: + articles = fetch.content_detail(identifier=identifier) + except Exception: + return None try: return articles[-1] except IndexError: @@ -228,7 +231,10 @@ async def fetch_medrxiv_article(identifier: str) -> Optional[RxivContentDetail]: Fetch an existing medRxiv article from Rxiv """ fetch = Rxiv("https://api.biorxiv.org", "medrxiv") - articles = fetch.content_detail(identifier=identifier) + try: + articles = fetch.content_detail(identifier=identifier) + except Exception: + return None try: return articles[-1] except IndexError: