Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 48f9d957 authored by Israel Yago Pereira's avatar Israel Yago Pereira
Browse files

Hide full url path when 404 error is thrown

parent b7f8aadc
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@
"""
Raise exception for an HTTP response is an error.
"""
from searx.exceptions import (SearxEngineCaptchaException, SearxEngineTooManyRequestsException,
from searx.exceptions import (SearxEngineAPIException, SearxEngineCaptchaException, SearxEngineTooManyRequestsException,
                              SearxEngineAccessDeniedException)


@@ -63,4 +63,7 @@ def raise_for_httperror(resp):
                                                   suspended_time=3600 * 24)
        if resp.status_code == 429:
            raise SearxEngineTooManyRequestsException()
        if resp.status_code == 404:
            message = f'(404) Resource not found for "{resp.url.host}". Are you sure the API endpoint is valid?'
            raise SearxEngineAPIException(message)
        resp.raise_for_status()
+5 −2
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@ from searx.exceptions import (SearxEngineAccessDeniedException, SearxEngineCaptc
from searx.metrology.error_recorder import record_exception, record_error

from searx.search.processors.abstract import EngineProcessor
from urllib.parse import urlparse


logger = logger.getChild('search.processor.online')
@@ -175,9 +176,11 @@ class OnlineProcessor(EngineProcessor):
            elif (issubclass(e.__class__, (httpx.HTTPError, httpx.StreamError))):
                result_container.add_unresponsive_engine(self.engine_name, 'HTTP error')
                # other requests exception
                response_url = urlparse(str(e.response.url))
                logger.exception("engine {0} : requests exception"
                                 "(search duration : {1} s, timeout: {2} s) : {3}"
                                 .format(self.engine_name, engine_time, timeout_limit, e))
                                 "(search duration : {1} s, timeout: {2} s) : "
                                 "Status code {3} while requesting {4}"
                                 .format(self.engine_name, engine_time, timeout_limit, e.response.status_code, response_url.hostname))
                http_exception = True
            elif (issubclass(e.__class__, SearxEngineCaptchaException)):
                result_container.add_unresponsive_engine(self.engine_name, 'CAPTCHA required')