kopia lustrzana https://github.com/snarfed/bridgy-fed
common.get_as2 bug fix: don't clobber werkzeug's HTTPException.response
store requests.Response in separate requests_response attrpull/79/head
rodzic
f4aefff6f4
commit
cdb9a519e6
|
@ -90,7 +90,7 @@ def _requests_fn(fn, url, parse_json=False, **kwargs):
|
|||
except ValueError:
|
||||
msg = "Couldn't parse response as JSON"
|
||||
logging.info(msg, exc_info=True)
|
||||
raise exc.HTTPBadGateway(msg)
|
||||
raise BadGateway(msg)
|
||||
|
||||
return resp
|
||||
|
||||
|
@ -112,13 +112,13 @@ def get_as2(url):
|
|||
:class:`requests.HTTPError`, :class:`werkzeug.exceptions.HTTPException`
|
||||
|
||||
If we raise a werkzeug HTTPException, it will have an additional
|
||||
response attribute with the last requests.Response we received.
|
||||
requests_response attribute with the last requests.Response we received.
|
||||
"""
|
||||
def _error(resp):
|
||||
msg = "Couldn't fetch %s as ActivityStreams 2" % url
|
||||
logging.warning(msg)
|
||||
err = BadGateway(msg)
|
||||
err.response = resp
|
||||
err.requests_response = resp
|
||||
raise err
|
||||
|
||||
resp = requests_get(url, headers=CONNEG_HEADERS_AS2_HTML)
|
||||
|
|
|
@ -166,11 +166,11 @@ class Webmention(View):
|
|||
try:
|
||||
self.target_resp = common.get_as2(target)
|
||||
except (requests.HTTPError, BadGateway) as e:
|
||||
self.target_resp = getattr(e, 'response', None)
|
||||
self.target_resp = getattr(e, 'requests_response', None)
|
||||
if self.target_resp and self.target_resp.status_code // 100 == 2:
|
||||
content_type = common.content_type(self.target_resp) or ''
|
||||
if content_type.startswith('text/html'):
|
||||
# TODO: pass e.response to try_salmon()'s target_resp
|
||||
# TODO: pass e.requests_response to try_salmon's target_resp
|
||||
continue # give up
|
||||
raise
|
||||
target_url = self.target_resp.url or target
|
||||
|
|
Ładowanie…
Reference in New Issue