Add missing `response.raise_for_status()` call to the `fetch_document` network helper

when fetching with given URL. Error status was already being raised correctly when
fetching by domain and path.
merge-requests/159/merge
Jason Robinson 2019-12-29 20:44:32 +02:00
rodzic f6b2bb6d05
commit 91dc3ca312
3 zmienionych plików z 7 dodań i 1 usunięć

Wyświetl plik

@ -6,6 +6,10 @@
* Don't crash loudly when fetching webfinger for Diaspora that does not contain XML.
* Add missing `response.raise_for_status()` call to the `fetch_document` network helper
when fetching with given URL. Error status was already being raised correctly when
fetching by domain and path.
## [0.19.0] - 2019-12-15
### Added

Wyświetl plik

@ -73,7 +73,7 @@ def fetch_nodeinfo_document(host):
return
doc, status_code, error = fetch_document(url=url)
if status_code >= 300 and not doc:
if not doc:
return
try:
doc = json.loads(doc)

Wyświetl plik

@ -63,6 +63,7 @@ def fetch_document(url=None, host=None, path="/", timeout=10, raise_ssl_errors=T
:arg path: Path without domain (defaults to "/")
:arg timeout: Seconds to wait for response (defaults to 10)
:arg raise_ssl_errors: Pass False if you want to try HTTP even for sites with SSL errors (default True)
:arg extra_headers: Optional extra headers dictionary to add to requests
:returns: Tuple of document (str or None), status code (int or None) and error (an exception class instance or None)
:raises ValueError: If neither url nor host are given as parameters
"""
@ -80,6 +81,7 @@ def fetch_document(url=None, host=None, path="/", timeout=10, raise_ssl_errors=T
try:
response = requests.get(url, timeout=timeout, headers=headers)
logger.debug("fetch_document: found document, code %s", response.status_code)
response.raise_for_status()
return response.text, response.status_code, None
except RequestException as ex:
logger.debug("fetch_document: exception %s", ex)