remote_actor: cleanly catch exceptions while fetching actors

This commit is contained in:
kaniini 2018-11-18 22:07:12 +00:00
parent e0d633b861
commit 69dfb04131

View file

@ -1,3 +1,4 @@
import logging
import aiohttp
from . import CONFIG
from .http_debug import http_debug
@ -15,7 +16,13 @@ async def fetch_actor(uri, force=False):
if uri in ACTORS and not force:
return ACTORS[uri]
async with aiohttp.ClientSession(trace_configs=[http_debug()]) as session:
async with session.get(uri, headers={'Accept': 'application/activity+json'}) as resp:
ACTORS[uri] = (await resp.json(encoding='utf-8', content_type=None))
return ACTORS[uri]
try:
async with aiohttp.ClientSession(trace_configs=[http_debug()]) as session:
async with session.get(uri, headers={'Accept': 'application/activity+json'}) as resp:
if resp.status_code != 200:
return None
ACTORS[uri] = (await resp.json(encoding='utf-8', content_type=None))
return ACTORS[uri]
except Exception as e:
logging.info('Caught %r while fetching actor %r.', e, uri)
return None