Files
zulip/zerver/lib/exceptions.py
Greg Price 6dfb46dc08 JsonableError: Rename status_code and rely more on its default.
With #5598 there will soon be an application-level error code
optionally associated with a `JsonableError`, so rename this
field to make clear that it specifically refers to an
HTTP status code.

Also take this opportunity to eliminate most of the places
that refer to it, which only do so to repeat the default value.
2017-07-24 16:41:22 -07:00

27 lines
739 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, http_status_code=400):
# type: (Text, int) -> None
self.msg = msg
self.http_status_code = http_status_code
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)