upload: Use the new ErrorCode system in our custom error classes.

All JsonableError subclasses now have corresponding ErrorCode values
of their own, reducing the number of different patterns for using
the new JsonableError API.
This commit is contained in:
Greg Price
2017-07-20 17:18:33 -07:00
committed by Tim Abbott
parent 9faa44af60
commit 37dbcefa58
2 changed files with 5 additions and 3 deletions

View File

@@ -31,6 +31,8 @@ class ErrorCode(AbstractEnum):
BAD_REQUEST = () # Generic name, from the name of HTTP 400.
REQUEST_VARIABLE_MISSING = ()
REQUEST_VARIABLE_INVALID = ()
BAD_IMAGE = ()
QUOTA_EXCEEDED = ()
BAD_NARROW = ()
UNAUTHORIZED_PRINCIPAL = ()

View File

@@ -11,7 +11,7 @@ from jinja2 import Markup as mark_safe
import unicodedata
from zerver.lib.avatar_hash import user_avatar_path
from zerver.lib.request import JsonableError
from zerver.lib.exceptions import JsonableError, ErrorCode
from zerver.lib.str_utils import force_text, force_str, NonBinaryStr
from boto.s3.bucket import Bucket
@@ -84,10 +84,10 @@ def random_name(bytes=60):
return base64.urlsafe_b64encode(os.urandom(bytes)).decode('utf-8')
class BadImageError(JsonableError):
pass
code = ErrorCode.BAD_IMAGE
class ExceededQuotaError(JsonableError):
pass
code = ErrorCode.QUOTA_EXCEEDED
def resize_avatar(image_data, size=DEFAULT_AVATAR_SIZE):
# type: (binary_type, int) -> binary_type