bluesky: misc minor XPRC error handling

pull/371/head
Ryan Barrett 2023-01-13 20:12:44 -08:00
rodzic a66fe4bdc2
commit c1148ee3de
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
4 zmienionych plików z 17 dodań i 2 usunięć

Wyświetl plik

@ -48,6 +48,10 @@ class XrpcActorTest(testutil.TestCase):
},
}, resp.json)
def test_getProfile_unset(self, _):
resp = self.client.get('/xrpc/app.bsky.actor.getProfile')
self.assertEqual(400, resp.status_code)
def test_getProfile_not_domain(self, _):
resp = self.client.get('/xrpc/app.bsky.actor.getProfile',
query_string={'actor': 'not a domain'})

Wyświetl plik

@ -100,6 +100,10 @@ class XrpcFeedTest(testutil.TestCase):
'feed': [POST_BSKY, REPLY_BSKY, REPOST_BSKY],
}, resp.json)
def test_getAuthorFeed_unset(self, _):
resp = self.client.get('/xrpc/app.bsky.feed.getAuthorFeed')
self.assertEqual(400, resp.status_code)
def test_getAuthorFeed_not_domain(self, _):
resp = self.client.get('/xrpc/app.bsky.feed.getAuthorFeed',
query_string={'author': 'not a domain'})
@ -127,6 +131,10 @@ class XrpcFeedTest(testutil.TestCase):
self.assertEqual(200, resp.status_code, resp.get_data(as_text=True))
self.assert_equals(POST_THREAD_BSKY, resp.json)
def test_getPostThread_unset(self, mock_get):
mock_get.return_value = requests_response(status=500)
resp = self.client.get('/xrpc/app.bsky.feed.getPostThread')
self.assertEqual(400, resp.status_code)
def test_getPostThread_fetch_fails(self, mock_get):
mock_get.return_value = requests_response(status=500)

Wyświetl plik

@ -19,7 +19,7 @@ def getProfile(input, actor=None):
"""
# TODO: actor is either handle or DID
# see actorWhereClause in atproto/packages/pds/src/db/util.ts
if not re.match(util.DOMAIN_RE, actor):
if not actor or not re.match(util.DOMAIN_RE, actor):
raise ValueError(f'{actor} is not a domain')
url = f'https://{actor}/'

Wyświetl plik

@ -18,7 +18,7 @@ def getAuthorFeed(input, author=None, limit=None, before=None):
"""
lexicons/app/bsky/feed/getAuthorFeed.json, feedViewPost.json
"""
if not re.match(util.DOMAIN_RE, author):
if not author or not re.match(util.DOMAIN_RE, author):
raise ValueError(f'{author} is not a domain')
url = f'https://{author}/'
@ -54,6 +54,9 @@ def getPostThread(input, uri=None, depth=None):
"""
lexicons/app/bsky/feed/getPostThread.json
"""
if not uri:
raise ValueError('Missing uri')
mf2 = util.fetch_mf2(uri, gateway=True)
logger.info(f'Got mf2: {json.dumps(mf2, indent=2)}')