diff options
| author | Alexandre Flament <alex@al-f.net> | 2020-12-11 14:52:18 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-12-11 14:52:18 +0100 |
| commit | 9f8ebeca4481344ce7bd773a4f64360da01f0a77 (patch) | |
| tree | 7834dc899b99db4ea3f9f81542e8e029bf5b7d04 /searx/poolrequests.py | |
| parent | 033f39bff7b3365256491014140e35aa1e974d4e (diff) | |
| parent | d703119d3a313a406482b121ee94c6afee3bc307 (diff) | |
Merge pull request #2375 from dalf/raise_for_errors
[enh] add raise_for_httperror
Diffstat (limited to 'searx/poolrequests.py')
| -rw-r--r-- | searx/poolrequests.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/searx/poolrequests.py b/searx/poolrequests.py index 1eedc84b8..25a6baed9 100644 --- a/searx/poolrequests.py +++ b/searx/poolrequests.py @@ -7,6 +7,7 @@ import requests from searx import settings from searx import logger +from searx.raise_for_httperror import raise_for_httperror logger = logger.getChild('poolrequests') @@ -156,6 +157,12 @@ def request(method, url, **kwargs): if timeout is not None: kwargs['timeout'] = timeout + # raise_for_error + check_for_httperror = True + if 'raise_for_httperror' in kwargs: + check_for_httperror = kwargs['raise_for_httperror'] + del kwargs['raise_for_httperror'] + # do request response = session.request(method=method, url=url, **kwargs) @@ -176,6 +183,10 @@ def request(method, url, **kwargs): if hasattr(threadLocal, 'total_time'): threadLocal.total_time += time_after_request - time_before_request + # raise an exception + if check_for_httperror: + raise_for_httperror(response) + return response |