From 55c29642a2c6588208494a145257f73de7799a9b Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Wed, 21 Oct 2020 16:39:30 -0700 Subject: improve search logging and exception chaining --- fatcat_scholar/search.py | 11 ++++++----- 1 file 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 -- cgit v1.2.3