Skip to content

Commit

Permalink
Merge pull request #172 from opensanctions/pudo/permid-error-handling
Browse files Browse the repository at this point in the history
Handle more permid decode errors
  • Loading branch information
pudo committed Aug 30, 2024
2 parents c58bf25 + 9535e03 commit 4bb03c8
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions nomenklatura/enrich/permid.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,12 @@ def fetch_permid(self, url: str) -> Optional[Dict[str, Any]]:
params = {"format": "json-ld"}
hidden = {"access-token": self.api_token}
res_raw = self.http_get_cached(url, params=params, hidden=hidden, cache_days=90)
if not len(res_raw):
try:
return cast(Dict[str, Any], json.loads(res_raw))
except Exception:
log.info("Invalid response from PermID: %s", url)
self.http_remove_cache(url, params=params)
log.info("Empty response from PermID: %s", url)
return None
return cast(Dict[str, Any], json.loads(res_raw))

def fetch_perm_org(self, entity: CE, url: str) -> Optional[CE]:
res = self.fetch_permid(url)
Expand Down

0 comments on commit 4bb03c8

Please sign in to comment.