activitypub: handle connection failures better in webmention discovery

fixes https://console.cloud.google.com/errors/CPj1-sSij7DcXQ
pull/79/head
Ryan Barrett 2021-09-01 08:19:38 -07:00
rodzic 17d2066008
commit e4d285523f
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
2 zmienionych plików z 19 dodań i 6 usunięć

Wyświetl plik

@ -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")
# send webmentions and store Responses
errors = []
errors = [] # stores (code, body) tuples
for target in targets:
if util.domain_from_link(target) == util.domain_from_link(source):
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'
logging.info('Success!')
except BaseException as e:
util.interpret_http_exception(e)
logging.warning(f'Failed! {e}')
errors.append(e)
errors.append(util.interpret_http_exception(e))
response.put()
if errors:
msg = 'Errors:\n' + '\n'.join(str(e) for e in errors)
error(msg, status=getattr(errors[0], 'http_status', None))
msg = 'Errors: ' + ', '.join(f'{code} {body}' for code, body in errors)
error(msg, status=int(errors[0][0] or 502))
def postprocess_as2(activity, target=None, key=None):

Wyświetl plik

@ -10,6 +10,7 @@ from oauth_dropins.webutil import util
from oauth_dropins.webutil.testutil import requests_response
from oauth_dropins.webutil.util import json_dumps, json_loads
import requests
from urllib3.exceptions import ReadTimeoutError
import activitypub
import common
@ -411,3 +412,17 @@ class ActivityPubTest(testutil.TestCase):
# TODO: bring back
# 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)