summaryrefslogtreecommitdiffstats
path: root/python/fatcat_web/search.py
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2020-07-28 16:50:24 -0700
committerBryan Newbold <bnewbold@robocracy.org>2020-07-28 16:50:24 -0700
commit76cec8852f6e431b1c87f7d25f8bd4404f1c67e1 (patch)
tree71138532359586d340ec7784c7543f826bac4abf /python/fatcat_web/search.py
parent1301f6ba6c6ea31bdbcd3619d7f235912726f30a (diff)
downloadfatcat-76cec8852f6e431b1c87f7d25f8bd4404f1c67e1.tar.gz
fatcat-76cec8852f6e431b1c87f7d25f8bd4404f1c67e1.zip
search: catch ES errors and display better
Diffstat (limited to 'python/fatcat_web/search.py')
-rw-r--r--python/fatcat_web/search.py22
1 files changed, 18 insertions, 4 deletions
diff --git a/python/fatcat_web/search.py b/python/fatcat_web/search.py
index fe0610e5..3fd7f9dc 100644
--- a/python/fatcat_web/search.py
+++ b/python/fatcat_web/search.py
@@ -15,6 +15,15 @@ import elasticsearch_dsl.response
from fatcat_web import app
+class FatcatSearchError(Exception):
+
+ def __init__(self, status_code: int, name: str, description: str = None):
+ if status_code == "N/A":
+ status_code = 503
+ self.status_code = status_code
+ self.name = name
+ self.description = description
+
@dataclass
class ReleaseQuery:
q: Optional[str] = None
@@ -109,14 +118,19 @@ def wrap_es_execution(search: Search) -> Any:
except elasticsearch.exceptions.RequestError as e:
# this is a "user" error
print("elasticsearch 400: " + str(e.info), file=sys.stderr)
+ description = None
if e.info.get("error", {}).get("root_cause", {}):
- raise ValueError(str(e.info["error"]["root_cause"][0].get("reason")))
- else:
- raise ValueError(str(e.info))
+ description = str(e.info["error"]["root_cause"][0].get("reason"))
+ raise FatcatSearchError(e.status_code, str(e.error), description)
+ except elasticsearch.exceptions.ConnectionError as e:
+ raise FatcatSearchError(e.status_code, "ConnectionError: search engine not available")
except elasticsearch.exceptions.TransportError as e:
# all other errors
print("elasticsearch non-200 status code: {}".format(e.info), file=sys.stderr)
- raise IOError(str(e.info))
+ description = None
+ if e.info.get("error", {}).get("root_cause", {}):
+ description = str(e.info["error"]["root_cause"][0].get("reason"))
+ raise FatcatSearchError(e.status_code, str(e.error), description)
return resp
def do_container_search(