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:
Greg Price
2017-07-20 17:06:40 -07:00
committed by Tim Abbott
parent 7cd621bc9d
commit 4837d4178d
2 changed files with 4 additions and 4 deletions

View File

@@ -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

View File

@@ -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