webhook_decorator: Support notifying bot owner on invalid JSON.

Our webhook-errors.log file is riddled with exceptions that are
logged when a webhook is incorrectly configured to send data in
a non-JSON format. To avoid this, api_key_only_webhook_view
now supports an additional argument, notify_bot_owner_on_invalid_json.
This argument, when True, will send a PM notification to the bot's
owner notifying them of the configuration issue.
This commit is contained in:
Eeshan Garg
2018-11-15 01:01:34 -03:30
committed by Tim Abbott
parent 71174d53cb
commit d9958610a4
5 changed files with 82 additions and 6 deletions

View File

@@ -28,6 +28,7 @@ class ErrorCode(AbstractEnum):
BAD_REQUEST = () # Generic name, from the name of HTTP 400.
REQUEST_VARIABLE_MISSING = ()
REQUEST_VARIABLE_INVALID = ()
INVALID_JSON = ()
BAD_IMAGE = ()
REALM_UPLOAD_QUOTA = ()
BAD_NARROW = ()
@@ -142,5 +143,12 @@ class RateLimited(PermissionDenied):
def __init__(self, msg: str="") -> None:
super().__init__(msg)
class InvalidJSONError(JsonableError):
code = ErrorCode.INVALID_JSON
@staticmethod
def msg_format() -> str:
return _("Malformed JSON")
class BugdownRenderingException(Exception):
pass