about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJohn Nduli2024-07-04 19:14:39 +0300
committerBonfaceKilz2024-07-05 14:38:11 +0300
commitbf85765831bb765aa7e6a66bbe2127575e985db9 (patch)
tree06442dcae3394a9c38832503814cc8a51d334adf
parent92e0c8b492e96f5875bc2bb1df3e043abde2f280 (diff)
downloadgenenetwork2-bf85765831bb765aa7e6a66bbe2127575e985db9.tar.gz
fix: cleaner handling for gsearch errors
-rw-r--r--gn2/wqflask/gsearch.py10
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)