mirror of
https://git.pleroma.social/pleroma/relay.git
synced 2024-11-12 18:58:00 +00:00
remote_actor: cleanly catch exceptions while fetching actors
This commit is contained in:
parent
e0d633b861
commit
69dfb04131
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue