mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 22:43:42 +00:00
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.
27 lines
739 B
Python
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)
|