summaryrefslogtreecommitdiffstats
path: root/fatcat_scholar/search.py
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@archive.org>2020-10-21 16:39:30 -0700
committerBryan Newbold <bnewbold@archive.org>2020-10-21 16:39:30 -0700
commit55c29642a2c6588208494a145257f73de7799a9b (patch)
tree3b324cc3200e2e6abe81f82d1e24e2b3a697edf3 /fatcat_scholar/search.py
parent0dbdee2d791b396d5bbe6a46933152f5a9346ae2 (diff)
downloadfatcat-scholar-55c29642a2c6588208494a145257f73de7799a9b.tar.gz
fatcat-scholar-55c29642a2c6588208494a145257f73de7799a9b.zip
improve search logging and exception chaining
Diffstat (limited to 'fatcat_scholar/search.py')
-rw-r--r--fatcat_scholar/search.py11
1 files changed, 6 insertions, 5 deletions
diff --git a/fatcat_scholar/search.py b/fatcat_scholar/search.py
index ecbae07..733ba82 100644
--- a/fatcat_scholar/search.py
+++ b/fatcat_scholar/search.py
@@ -3,6 +3,7 @@ Helpers to make elasticsearch queries.
"""
import sys
+import logging
import datetime
from gettext import gettext
from typing import List, Optional, Any
@@ -316,15 +317,15 @@ def do_fulltext_search(
resp = search.execute()
except elasticsearch.exceptions.RequestError as e:
# this is a "user" error
- print("elasticsearch 400: " + str(e.info), file=sys.stderr)
+ logging.warn("elasticsearch 400: " + str(e.info))
if e.info.get("error", {}).get("root_cause", {}):
- raise ValueError(str(e.info["error"]["root_cause"][0].get("reason")))
+ raise ValueError(str(e.info["error"]["root_cause"][0].get("reason"))) from e
else:
- raise ValueError(str(e.info))
+ raise ValueError(str(e.info)) from e
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))
+ logging.warn("elasticsearch non-200 status code: {}".format(e.info))
+ raise IOError(str(e.info)) from e
query_delta = datetime.datetime.now() - query_start
# convert from API objects to dicts