kopia lustrzana https://github.com/snarfed/bridgy-fed
activitypub: handle connection failures better in webmention discovery
fixes https://console.cloud.google.com/errors/CPj1-sSij7DcXQpull/79/head
rodzic
17d2066008
commit
e4d285523f
10
common.py
10
common.py
|
@ -189,7 +189,7 @@ def send_webmentions(activity_wrapped, proxy=None, **response_props):
|
||||||
error("Couldn't find any target URLs in inReplyTo, object, or mention tags")
|
error("Couldn't find any target URLs in inReplyTo, object, or mention tags")
|
||||||
|
|
||||||
# send webmentions and store Responses
|
# send webmentions and store Responses
|
||||||
errors = []
|
errors = [] # stores (code, body) tuples
|
||||||
for target in targets:
|
for target in targets:
|
||||||
if util.domain_from_link(target) == util.domain_from_link(source):
|
if util.domain_from_link(target) == util.domain_from_link(source):
|
||||||
logging.info('Skipping same-domain webmention from %s to %s',
|
logging.info('Skipping same-domain webmention from %s to %s',
|
||||||
|
@ -211,14 +211,12 @@ def send_webmentions(activity_wrapped, proxy=None, **response_props):
|
||||||
response.status = 'complete'
|
response.status = 'complete'
|
||||||
logging.info('Success!')
|
logging.info('Success!')
|
||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
util.interpret_http_exception(e)
|
errors.append(util.interpret_http_exception(e))
|
||||||
logging.warning(f'Failed! {e}')
|
|
||||||
errors.append(e)
|
|
||||||
response.put()
|
response.put()
|
||||||
|
|
||||||
if errors:
|
if errors:
|
||||||
msg = 'Errors:\n' + '\n'.join(str(e) for e in errors)
|
msg = 'Errors: ' + ', '.join(f'{code} {body}' for code, body in errors)
|
||||||
error(msg, status=getattr(errors[0], 'http_status', None))
|
error(msg, status=int(errors[0][0] or 502))
|
||||||
|
|
||||||
|
|
||||||
def postprocess_as2(activity, target=None, key=None):
|
def postprocess_as2(activity, target=None, key=None):
|
||||||
|
|
|
@ -10,6 +10,7 @@ from oauth_dropins.webutil import util
|
||||||
from oauth_dropins.webutil.testutil import requests_response
|
from oauth_dropins.webutil.testutil import requests_response
|
||||||
from oauth_dropins.webutil.util import json_dumps, json_loads
|
from oauth_dropins.webutil.util import json_dumps, json_loads
|
||||||
import requests
|
import requests
|
||||||
|
from urllib3.exceptions import ReadTimeoutError
|
||||||
|
|
||||||
import activitypub
|
import activitypub
|
||||||
import common
|
import common
|
||||||
|
@ -411,3 +412,17 @@ class ActivityPubTest(testutil.TestCase):
|
||||||
|
|
||||||
# TODO: bring back
|
# TODO: bring back
|
||||||
# self.assertEqual([other], Follower.query().fetch())
|
# self.assertEqual([other], Follower.query().fetch())
|
||||||
|
|
||||||
|
def test_inbox_webmention_discovery_connection_fails(self, mock_head,
|
||||||
|
mock_get, mock_post):
|
||||||
|
mock_get.side_effect = [
|
||||||
|
# source actor
|
||||||
|
requests_response(LIKE_WITH_ACTOR['actor'],
|
||||||
|
headers={'Content-Type': common.CONTENT_TYPE_AS2}),
|
||||||
|
# target post webmention discovery
|
||||||
|
ReadTimeoutError(None, None, None),
|
||||||
|
]
|
||||||
|
|
||||||
|
got = self.client.post('/foo.com/inbox', json=LIKE)
|
||||||
|
self.assertEqual(504, got.status_code)
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue