inbox: return error on unhandled message types
This commit is contained in:
parent
e5bdb40964
commit
3cbee693a2
|
@ -44,7 +44,7 @@ def fetch_actor(url):
|
|||
return data
|
||||
|
||||
|
||||
def fetch(url, sign=False, cache=True):
|
||||
def fetch(url, sign=False, headers={}, cache=True):
|
||||
cached_data = fetch_cache.fetch(url)
|
||||
|
||||
if cached_data and cache:
|
||||
|
@ -54,7 +54,8 @@ def fetch(url, sign=False, cache=True):
|
|||
with db.session as s:
|
||||
response = client.request(url,
|
||||
privkey = s.get.config('privkey'),
|
||||
keyid = f'https://{config.host}/actor#main-key'
|
||||
keyid = f'https://{config.host}/actor#main-key',
|
||||
headers = {}
|
||||
)
|
||||
|
||||
else:
|
||||
|
@ -89,7 +90,7 @@ def get_inbox(actor):
|
|||
return actor.inbox
|
||||
|
||||
|
||||
def push_message(inbox, message):
|
||||
def push_message(inbox, message, headers={}):
|
||||
with db.session as s:
|
||||
try:
|
||||
response = client.request(
|
||||
|
|
|
@ -24,10 +24,17 @@ class ProcessData:
|
|||
|
||||
if not self.actor:
|
||||
logging.verbose(f'Failed to fetch actor: {data.actor}')
|
||||
self.new_response = response.json('Failed to fetch actor.', status=401)
|
||||
self.new_response = response.text('Failed to fetch actor.', status=401)
|
||||
return
|
||||
|
||||
self.new_response = getattr(self, f'cmd_{self.type}')()
|
||||
|
||||
@property
|
||||
def func(self):
|
||||
return getattr(self, f'cmd_{self.type}')
|
||||
|
||||
|
||||
def error(self, *message):
|
||||
self.new_response = self.response.json({'error': ' '.join(message)})
|
||||
|
||||
|
||||
def cmd_follow(self):
|
||||
|
@ -127,3 +134,7 @@ class ProcessData:
|
|||
|
||||
def cmd_create(self):
|
||||
return self.cmd_announce()
|
||||
|
||||
|
||||
#def cmd_delete(self):
|
||||
#pass
|
||||
|
|
|
@ -127,11 +127,14 @@ class UnciaActor(View):
|
|||
|
||||
|
||||
async def post(self, request, response):
|
||||
data = ProcessData(request, response, request.data.json)
|
||||
processor = ProcessData(request, response, request.data.json)
|
||||
|
||||
# return error to let mastodon retry instead of having to re-add relay
|
||||
return data.new_response or response.text('UvU', status=202)
|
||||
#return response.text('Merp! uvu')
|
||||
try:
|
||||
data = processor.func()
|
||||
except AttributeError:
|
||||
return processor.error('Message type unhandled:', processor.type)
|
||||
|
||||
return data or response.text('UvU', status=202)
|
||||
|
||||
|
||||
class UnciaNodeinfo(View):
|
||||
|
|
Loading…
Reference in a new issue