Files
zulip/zerver/lib/exceptions.py
Greg Price 4837d4178d JsonableError: Make http_status_code a class attribute only.
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.
2017-07-24 16:41:22 -07:00

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)