Fix exception in webhook validation

This commit is contained in:
amcmanu3 2024-08-06 14:10:53 -04:00
parent 5c9b59f9e8
commit 279ad61a1b
2 changed files with 20 additions and 4 deletions

View File

@ -99,13 +99,21 @@ class ApiServersServerWebhooksIndexHandler(BaseApiHandler):
try:
validate(data, new_webhook_schema)
except ValidationError as e:
except ValidationError as why:
offending_key = None
if why.get("fill", None):
offending_key = why.path[0] if why.path else None
err = f"""{self.translator.translate(
"validators",
why.schema.get("error"),
self.controller.users.get_user_lang_by_id(auth_data[4]["user_id"]),
)} {offending_key}"""
return self.finish_json(
400,
{
"status": "error",
"error": "INVALID_JSON_SCHEMA",
"error_data": str(e),
"error_data": f"{str(err)}",
},
)

View File

@ -137,13 +137,21 @@ class ApiServersServerWebhooksManagementIndexHandler(BaseApiHandler):
try:
validate(data, webhook_patch_schema)
except ValidationError as e:
except ValidationError as why:
offending_key = None
if why.get("fill", None):
offending_key = why.path[0] if why.path else None
err = f"""{self.translator.translate(
"validators",
why.schema.get("error"),
self.controller.users.get_user_lang_by_id(auth_data[4]["user_id"]),
)} {offending_key}"""
return self.finish_json(
400,
{
"status": "error",
"error": "INVALID_JSON_SCHEMA",
"error_data": str(e),
"error_data": f"{str(err)}",
},
)