Show length error when Configs provided are too long (#1920)

* Show an error when a config is too long
This commit is contained in:
Ife Lawal
2021-06-26 00:04:36 -04:00
committed by GitHub
parent dd05f57b6a
commit 08ff0f2ed6
6 changed files with 52 additions and 4 deletions

View File

@@ -89,6 +89,9 @@ class ConfigList(Resource):
response = schema.load(req)
if response.errors:
# Inject config key into error
config_key = response.data["key"]
response.errors["value"][0] = f"{config_key} config is too long"
return {"success": False, "errors": response.errors}, 400
db.session.add(response.data)
@@ -109,8 +112,15 @@ class ConfigList(Resource):
)
def patch(self):
req = request.get_json()
schema = ConfigSchema()
for key, value in req.items():
response = schema.load({"key": key, "value": value})
if response.errors:
# Inject config key into error
config_key = response.data["key"]
response.errors["value"][0] = f"{config_key} config is too long"
return {"success": False, "errors": response.errors}, 400
set_config(key=key, value=value)
clear_config()