mirror of
https://github.com/zulip/zulip.git
synced 2025-11-13 10:26:28 +00:00
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.
This commit is contained in:
@@ -7,10 +7,9 @@ class JsonableError(Exception):
|
|||||||
msg = None # type: Text
|
msg = None # type: Text
|
||||||
http_status_code = 400 # type: int
|
http_status_code = 400 # type: int
|
||||||
|
|
||||||
def __init__(self, msg, http_status_code=400):
|
def __init__(self, msg):
|
||||||
# type: (Text, int) -> None
|
# type: (Text) -> None
|
||||||
self.msg = msg
|
self.msg = msg
|
||||||
self.http_status_code = http_status_code
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
# type: () -> str
|
# type: () -> str
|
||||||
|
|||||||
@@ -35,10 +35,11 @@ from six.moves import urllib
|
|||||||
import six
|
import six
|
||||||
|
|
||||||
class PrincipalError(JsonableError):
|
class PrincipalError(JsonableError):
|
||||||
|
http_status_code = 403
|
||||||
|
|
||||||
def __init__(self, principal):
|
def __init__(self, principal):
|
||||||
# type: (Text) -> None
|
# type: (Text) -> None
|
||||||
self.principal = principal # type: Text
|
self.principal = principal # type: Text
|
||||||
self.http_status_code = 403 # type: int
|
|
||||||
|
|
||||||
def to_json_error_msg(self):
|
def to_json_error_msg(self):
|
||||||
# type: () -> Text
|
# type: () -> Text
|
||||||
|
|||||||
Reference in New Issue
Block a user