diff options
author | John Nduli | 2024-07-04 19:14:39 +0300 |
---|---|---|
committer | Alexander_Kabui | 2024-08-28 15:02:45 +0300 |
commit | 7f707aaca67e21b43d4c9f29a460effb5129c9a4 (patch) | |
tree | 2d29eab0ad9c42a264e1fba0ffc201e2f260863c /gn2 | |
parent | 6d6a22d592ec6f55a74769d5b9a13aea7eadfc8b (diff) | |
download | genenetwork2-7f707aaca67e21b43d4c9f29a460effb5129c9a4.tar.gz |
fix: cleaner handling for gsearch errors
Diffstat (limited to 'gn2')
-rw-r--r-- | gn2/wqflask/gsearch.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/gn2/wqflask/gsearch.py b/gn2/wqflask/gsearch.py index cad6db94..2a214cf8 100644 --- a/gn2/wqflask/gsearch.py +++ b/gn2/wqflask/gsearch.py @@ -28,10 +28,16 @@ class GSearch: hmac = curry(3, lambda trait_name, dataset, data_hmac: f"{trait_name}:{dataset}:{data_hmac}") convert_lod = lambda x: x / 4.61 self.trait_list = [] - for i, trait in enumerate(requests.get( + response = requests.get( urljoin(GN3_LOCAL_URL, "/api/search?" + urlencode({"query": self.terms, "type": self.type, - "per_page": MAX_SEARCH_RESULTS}))).json()): + "per_page": MAX_SEARCH_RESULTS}))) + if response.status_code == 400 and "parsererror" in response.text.lower(): + raise ValueError(f"Query `{self.terms}` has a problem: {response.json()}") + response.raise_for_status() + response_json = response.json() + + for i, trait in enumerate(response_json): trait = MonadicDict(trait) trait["index"] = Just(i) trait["location_repr"] = (Maybe.apply(chr_mb) |