Skip to content

Commit

Permalink
upgraded exception for get_vocab_by_category() (#308)
Browse files Browse the repository at this point in the history
* upgraded error for `get_vocab_by_category()`

* formatted with trunk
  • Loading branch information
nh916 authored Sep 1, 2023
1 parent 8df4f1b commit 1686fbd
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/cript/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,12 +514,14 @@ def get_vocab_by_category(self, category: VocabCategories) -> List[dict]:
if category.value in self._vocabulary:
return self._vocabulary[category.value]

vocabulary_category_url: str = f"{self.host}/cv/{category.value}/"

# if vocabulary category is not in cache, then get it from API and cache it
response = requests.get(f"{self.host}/cv/{category.value}/", timeout=_API_TIMEOUT).json()
response: Dict = requests.get(url=vocabulary_category_url, timeout=_API_TIMEOUT).json()

if response["code"] != 200:
# TODO give a better CRIPT custom Exception
raise Exception(f"while getting controlled vocabulary from CRIPT for {category}, " f"the API responded with http {response} ")
raise APIError(api_error=str(response), http_method="GET", api_url=vocabulary_category_url)

# add to cache
self._vocabulary[category.value] = response["data"]
Expand Down

0 comments on commit 1686fbd

Please sign in to comment.