summaryrefslogtreecommitdiff
path: root/searx/search/processors
diff options
context:
space:
mode:
authorAlexandre Flament <alex@al-f.net>2021-04-26 11:12:02 +0200
committerMarkus Heiser <markus.heiser@darmarit.de>2021-04-27 14:20:07 +0200
commitb1557b544368b416c158c13f12946859abbe00e0 (patch)
tree9cf9ce57d66b7701051a41c2757b5c92fa3abd09 /searx/search/processors
parent9b482e8fccfc5e5504e4c8abdb60ce5c11678018 (diff)
[mod] processors: show identical error messages on /search and /stats
Diffstat (limited to 'searx/search/processors')
-rw-r--r--searx/search/processors/abstract.py26
-rw-r--r--searx/search/processors/offline.py2
-rw-r--r--searx/search/processors/online.py12
3 files changed, 23 insertions, 17 deletions
diff --git a/searx/search/processors/abstract.py b/searx/search/processors/abstract.py
index 854f6df6..2a36222d 100644
--- a/searx/search/processors/abstract.py
+++ b/searx/search/processors/abstract.py
@@ -59,22 +59,28 @@ class EngineProcessor(ABC):
key = id(key) if key else self.engine_name
self.suspended_status = SUSPENDED_STATUS.setdefault(key, SuspendedStatus())
- def handle_exception(self, result_container, reason, exception, suspend=False, display_exception=True):
+ def handle_exception(self, result_container, exception_or_message, suspend=False):
# update result_container
- error_message = str(exception) if display_exception and exception else None
- result_container.add_unresponsive_engine(self.engine_name, reason, error_message)
+ if isinstance(exception_or_message, BaseException):
+ exception_class = exception_or_message.__class__
+ module_name = getattr(exception_class, '__module__', 'builtins')
+ module_name = '' if module_name == 'builtins' else module_name + '.'
+ error_message = module_name + exception_class.__qualname__
+ else:
+ error_message = exception_or_message
+ result_container.add_unresponsive_engine(self.engine_name, error_message)
# metrics
counter_inc('engine', self.engine_name, 'search', 'count', 'error')
- if exception:
- count_exception(self.engine_name, exception)
+ if isinstance(exception_or_message, BaseException):
+ count_exception(self.engine_name, exception_or_message)
else:
- count_error(self.engine_name, reason)
+ count_error(self.engine_name, exception_or_message)
# suspend the engine ?
if suspend:
suspended_time = None
- if isinstance(exception, SearxEngineAccessDeniedException):
- suspended_time = exception.suspended_time
- self.suspended_status.suspend(suspended_time, reason) # pylint: disable=no-member
+ if isinstance(exception_or_message, SearxEngineAccessDeniedException):
+ suspended_time = exception_or_message.suspended_time
+ self.suspended_status.suspend(suspended_time, error_message) # pylint: disable=no-member
def _extend_container_basic(self, result_container, start_time, search_results):
# update result_container
@@ -91,7 +97,7 @@ class EngineProcessor(ABC):
def extend_container(self, result_container, start_time, search_results):
if getattr(threading.current_thread(), '_timeout', False):
# the main thread is not waiting anymore
- self.handle_exception(result_container, 'Timeout', None)
+ self.handle_exception(result_container, 'timeout', None)
else:
# check if the engine accepted the request
if search_results is not None:
diff --git a/searx/search/processors/offline.py b/searx/search/processors/offline.py
index 5186b346..ad03fed4 100644
--- a/searx/search/processors/offline.py
+++ b/searx/search/processors/offline.py
@@ -22,5 +22,5 @@ class OfflineProcessor(EngineProcessor):
# do not record the error
logger.exception('engine {0} : invalid input : {1}'.format(self.engine_name, e))
except Exception as e:
- self.handle_exception(result_container, 'unexpected crash', e)
+ self.handle_exception(result_container, e)
logger.exception('engine {0} : exception : {1}'.format(self.engine_name, e))
diff --git a/searx/search/processors/online.py b/searx/search/processors/online.py
index c3993702..57422c00 100644
--- a/searx/search/processors/online.py
+++ b/searx/search/processors/online.py
@@ -130,7 +130,7 @@ class OnlineProcessor(EngineProcessor):
self.extend_container(result_container, start_time, search_results)
except (httpx.TimeoutException, asyncio.TimeoutError) as e:
# requests timeout (connect or read)
- self.handle_exception(result_container, 'HTTP timeout', e, suspend=True, display_exception=False)
+ self.handle_exception(result_container, e, suspend=True)
logger.error("engine {0} : HTTP requests timeout"
"(search duration : {1} s, timeout: {2} s) : {3}"
.format(self.engine_name, time() - start_time,
@@ -138,23 +138,23 @@ class OnlineProcessor(EngineProcessor):
e.__class__.__name__))
except (httpx.HTTPError, httpx.StreamError) as e:
# other requests exception
- self.handle_exception(result_container, 'HTTP error', e, suspend=True, display_exception=False)
+ self.handle_exception(result_container, e, suspend=True)
logger.exception("engine {0} : requests exception"
"(search duration : {1} s, timeout: {2} s) : {3}"
.format(self.engine_name, time() - start_time,
timeout_limit,
e))
except SearxEngineCaptchaException as e:
- self.handle_exception(result_container, 'CAPTCHA required', e, suspend=True, display_exception=False)
+ self.handle_exception(result_container, e, suspend=True)
logger.exception('engine {0} : CAPTCHA'.format(self.engine_name))
except SearxEngineTooManyRequestsException as e:
- self.handle_exception(result_container, 'too many requests', e, suspend=True, display_exception=False)
+ self.handle_exception(result_container, e, suspend=True)
logger.exception('engine {0} : Too many requests'.format(self.engine_name))
except SearxEngineAccessDeniedException as e:
- self.handle_exception(result_container, 'blocked', e, suspend=True, display_exception=False)
+ self.handle_exception(result_container, e, suspend=True)
logger.exception('engine {0} : Searx is blocked'.format(self.engine_name))
except Exception as e:
- self.handle_exception(result_container, 'unexpected crash', e, display_exception=False)
+ self.handle_exception(result_container, e)
logger.exception('engine {0} : exception : {1}'.format(self.engine_name, e))
def get_default_tests(self):