Handle missing bodies more gracefully
This commit is contained in:
parent
33b1b8e39f
commit
9f8c79a5ee
1 changed files with 12 additions and 2 deletions
|
@ -1,3 +1,5 @@
|
|||
import json
|
||||
from json.decoder import JSONDecodeError
|
||||
import logging
|
||||
|
||||
from aiohttp.web import HTTPUnauthorized, Request
|
||||
|
@ -221,14 +223,20 @@ async def set_config(request: Request):
|
|||
return Response.new_error(403, "access denied", "json")
|
||||
|
||||
# FIXME: config doesn't have a way to go from JSON or update, using dict stuff
|
||||
new_config = await request.json()
|
||||
text = await request.text()
|
||||
try:
|
||||
new_config = json.loads(text)
|
||||
except JSONDecodeError as e:
|
||||
logging.exception(f"Unable to load config {text!r}")
|
||||
return Response.new_error(400, "bad request", "json")
|
||||
|
||||
request.app.config.update(new_config)
|
||||
|
||||
# If there are pending follows which are NOW whitelisted, allow them
|
||||
if request.app.config.whitelist_enabled:
|
||||
# If there are pending follows which are NOW whitelisted, allow them
|
||||
for domain in request.app.config.whitelist:
|
||||
if (pending_follow := request.app.database.get_request(domain, False)):
|
||||
logging.info(f"Acknowledging queued follow request from {domain}...")
|
||||
await misc.request(
|
||||
actor.shared_inbox,
|
||||
misc.Message.new_response(
|
||||
|
@ -249,6 +257,8 @@ async def set_config(request: Request):
|
|||
|
||||
request.app.database.del_request(domain)
|
||||
|
||||
# FIXME: If there are EXISTING follows which are NO LONGER allowed/are blacklisted, drop them
|
||||
|
||||
request.app.database.save()
|
||||
|
||||
request.app.config.save()
|
||||
|
|
Loading…
Reference in a new issue