mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 14:03:30 +00:00
This simplifies things for all codepaths not involving this feature. Using this feature becomes slightly easier when you're already defining a subclass, but now requires you to define a subclass. Currently we use it just once out of >100 uses of JsonableError, and that use already has a subclass, so this seems like a win.
26 lines
663 B
Python
26 lines
663 B
Python
from __future__ import absolute_import
|
|
from typing import Text
|
|
|
|
from django.core.exceptions import PermissionDenied
|
|
|
|
class JsonableError(Exception):
|
|
msg = None # type: Text
|
|
http_status_code = 400 # type: int
|
|
|
|
def __init__(self, msg):
|
|
# type: (Text) -> None
|
|
self.msg = msg
|
|
|
|
def __str__(self):
|
|
# type: () -> str
|
|
return self.to_json_error_msg() # type: ignore # remove once py3-only
|
|
|
|
def to_json_error_msg(self):
|
|
# type: () -> Text
|
|
return self.msg
|
|
|
|
class RateLimited(PermissionDenied):
|
|
def __init__(self, msg=""):
|
|
# type: (str) -> None
|
|
super(RateLimited, self).__init__(msg)
|