mirror of
https://github.com/searxng/searxng.git
synced 2024-11-26 21:01:01 +00:00
show engine errors in infobox && add new error alert
This commit is contained in:
parent
3bd5ce6595
commit
243d3e4298
6 changed files with 29 additions and 5 deletions
|
@ -135,6 +135,7 @@ class ResultContainer(object):
|
||||||
self._number_of_results = []
|
self._number_of_results = []
|
||||||
self._ordered = False
|
self._ordered = False
|
||||||
self.paging = False
|
self.paging = False
|
||||||
|
self.unresponsive_engines = []
|
||||||
|
|
||||||
def extend(self, engine_name, results):
|
def extend(self, engine_name, results):
|
||||||
for result in list(results):
|
for result in list(results):
|
||||||
|
@ -304,3 +305,6 @@ class ResultContainer(object):
|
||||||
if not resultnum_sum or not self._number_of_results:
|
if not resultnum_sum or not self._number_of_results:
|
||||||
return 0
|
return 0
|
||||||
return resultnum_sum / len(self._number_of_results)
|
return resultnum_sum / len(self._number_of_results)
|
||||||
|
|
||||||
|
def add_unresponsive_engine(self, engine_name):
|
||||||
|
self.unresponsive_engines.append(engine_name)
|
||||||
|
|
|
@ -20,6 +20,7 @@ import sys
|
||||||
import threading
|
import threading
|
||||||
from time import time
|
from time import time
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
from flask_babel import gettext
|
||||||
import requests.exceptions
|
import requests.exceptions
|
||||||
import searx.poolrequests as requests_lib
|
import searx.poolrequests as requests_lib
|
||||||
from searx.engines import (
|
from searx.engines import (
|
||||||
|
@ -133,18 +134,21 @@ def search_one_request_safe(engine_name, query, request_params, result_container
|
||||||
requests_exception = False
|
requests_exception = False
|
||||||
|
|
||||||
if (issubclass(e.__class__, requests.exceptions.Timeout)):
|
if (issubclass(e.__class__, requests.exceptions.Timeout)):
|
||||||
|
result_container.add_unresponsive_engine((engine_name, gettext('timeout')))
|
||||||
# requests timeout (connect or read)
|
# requests timeout (connect or read)
|
||||||
logger.error("engine {0} : HTTP requests timeout"
|
logger.error("engine {0} : HTTP requests timeout"
|
||||||
"(search duration : {1} s, timeout: {2} s) : {3}"
|
"(search duration : {1} s, timeout: {2} s) : {3}"
|
||||||
.format(engine_name, search_duration, timeout_limit, e.__class__.__name__))
|
.format(engine_name, search_duration, timeout_limit, e.__class__.__name__))
|
||||||
requests_exception = True
|
requests_exception = True
|
||||||
elif (issubclass(e.__class__, requests.exceptions.RequestException)):
|
elif (issubclass(e.__class__, requests.exceptions.RequestException)):
|
||||||
|
result_container.add_unresponsive_engine((engine_name, gettext('request exception')))
|
||||||
# other requests exception
|
# other requests exception
|
||||||
logger.exception("engine {0} : requests exception"
|
logger.exception("engine {0} : requests exception"
|
||||||
"(search duration : {1} s, timeout: {2} s) : {3}"
|
"(search duration : {1} s, timeout: {2} s) : {3}"
|
||||||
.format(engine_name, search_duration, timeout_limit, e))
|
.format(engine_name, search_duration, timeout_limit, e))
|
||||||
requests_exception = True
|
requests_exception = True
|
||||||
else:
|
else:
|
||||||
|
result_container.add_unresponsive_engine((engine_name, gettext('unexpected crash')))
|
||||||
# others errors
|
# others errors
|
||||||
logger.exception('engine {0} : exception : {1}'.format(engine_name, e))
|
logger.exception('engine {0} : exception : {1}'.format(engine_name, e))
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
{% from 'oscar/macros.html' import icon %}
|
{% from 'oscar/macros.html' import icon %}
|
||||||
|
{% if unresponsive_engines %}
|
||||||
|
<div class="alert alert-danger fade in" role="alert">
|
||||||
|
<p><strong class="lead">{{ icon('remove-sign') }} {{ _('Error!') }}</strong> {{ _('Engines cannot retrieve results.') }}</p>
|
||||||
|
<p><small>{{ _('Please, try again later or find another searx instance.') }}</small></p>
|
||||||
|
</div>
|
||||||
|
{% else %}
|
||||||
<div class="alert alert-info fade in" role="alert">
|
<div class="alert alert-info fade in" role="alert">
|
||||||
<button class="close" data-dismiss="alert" type="button">
|
|
||||||
<span aria-hidden="true">×</span>
|
|
||||||
<span class="sr-only">{{ _('Close') }}</span>
|
|
||||||
</button>
|
|
||||||
<strong class="lead">{{ icon('info-sign') }} {{ _('Sorry!') }}</strong>
|
<strong class="lead">{{ icon('info-sign') }} {{ _('Sorry!') }}</strong>
|
||||||
{{ _('we didn\'t find any results. Please use another query or search in more categories.') }}
|
{{ _('we didn\'t find any results. Please use another query or search in more categories.') }}
|
||||||
</div>
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
|
@ -94,6 +94,16 @@
|
||||||
{% if number_of_results != '0' %}
|
{% if number_of_results != '0' %}
|
||||||
<p><small>{{ _('Number of results') }}: {{ number_of_results }}</small></p>
|
<p><small>{{ _('Number of results') }}: {{ number_of_results }}</small></p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% if unresponsive_engines and results|length >= 1 %}
|
||||||
|
<div class="alert alert-danger fade in" role="alert">
|
||||||
|
<p>{{ _('Engines cannot retrieve results') }}:</p>
|
||||||
|
{% for engine_name, error_type in unresponsive_engines %}
|
||||||
|
{{ engine_name }} ({{ error_type }}){% if not loop.last %}, {% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% if infoboxes %}
|
{% if infoboxes %}
|
||||||
{% for infobox in infoboxes %}
|
{% for infobox in infoboxes %}
|
||||||
{% include 'oscar/infobox.html' %}
|
{% include 'oscar/infobox.html' %}
|
||||||
|
|
|
@ -534,7 +534,8 @@ def index():
|
||||||
'answers': list(result_container.answers),
|
'answers': list(result_container.answers),
|
||||||
'corrections': list(result_container.corrections),
|
'corrections': list(result_container.corrections),
|
||||||
'infoboxes': result_container.infoboxes,
|
'infoboxes': result_container.infoboxes,
|
||||||
'suggestions': list(result_container.suggestions)}),
|
'suggestions': list(result_container.suggestions),
|
||||||
|
'unresponsive_engines': list(result_container.unresponsive_engines)}),
|
||||||
mimetype='application/json')
|
mimetype='application/json')
|
||||||
elif output_format == 'csv':
|
elif output_format == 'csv':
|
||||||
csv = UnicodeWriter(StringIO())
|
csv = UnicodeWriter(StringIO())
|
||||||
|
@ -573,6 +574,7 @@ def index():
|
||||||
corrections=result_container.corrections,
|
corrections=result_container.corrections,
|
||||||
infoboxes=result_container.infoboxes,
|
infoboxes=result_container.infoboxes,
|
||||||
paging=result_container.paging,
|
paging=result_container.paging,
|
||||||
|
unresponsive_engines=result_container.unresponsive_engines,
|
||||||
current_language=search_query.lang,
|
current_language=search_query.lang,
|
||||||
base_url=get_base_url(),
|
base_url=get_base_url(),
|
||||||
theme=get_current_theme_name(),
|
theme=get_current_theme_name(),
|
||||||
|
|
|
@ -39,6 +39,7 @@ class ViewsTestCase(SearxTestCase):
|
||||||
corrections=set(),
|
corrections=set(),
|
||||||
suggestions=set(),
|
suggestions=set(),
|
||||||
infoboxes=[],
|
infoboxes=[],
|
||||||
|
unresponsive_engines=[],
|
||||||
results=self.test_results,
|
results=self.test_results,
|
||||||
results_number=lambda: 3,
|
results_number=lambda: 3,
|
||||||
results_length=lambda: len(self.test_results))
|
results_length=lambda: len(self.test_results))
|
||||||
|
|
Loading…
Reference in a new issue