mirror of
https://github.com/zulip/zulip.git
synced 2025-11-13 02:17:19 +00:00
JsonableError: Rename message from error to msg.
The whole thing is an error, so "message" is a more apt word for the error message specifically. We abbreviate that as `msg` in the actual HTTP responses and in the signatures of `json_error` and friends, so do the same here.
This commit is contained in:
@@ -458,7 +458,7 @@ def authenticated_rest_api_view(is_webhook=False):
|
|||||||
# profile is a Union[UserProfile, RemoteZulipServer]
|
# profile is a Union[UserProfile, RemoteZulipServer]
|
||||||
profile = validate_api_key(request, role, api_key, is_webhook)
|
profile = validate_api_key(request, role, api_key, is_webhook)
|
||||||
except JsonableError as e:
|
except JsonableError as e:
|
||||||
return json_unauthorized(e.error)
|
return json_unauthorized(e.msg)
|
||||||
request.user = profile
|
request.user = profile
|
||||||
if is_remote_server(role):
|
if is_remote_server(role):
|
||||||
assert isinstance(profile, RemoteZulipServer) # type: ignore # https://github.com/python/mypy/issues/2957
|
assert isinstance(profile, RemoteZulipServer) # type: ignore # https://github.com/python/mypy/issues/2957
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ class RegistrationForm(forms.Form):
|
|||||||
try:
|
try:
|
||||||
return check_full_name(self.cleaned_data['full_name'])
|
return check_full_name(self.cleaned_data['full_name'])
|
||||||
except JsonableError as e:
|
except JsonableError as e:
|
||||||
raise ValidationError(e.error)
|
raise ValidationError(e.msg)
|
||||||
|
|
||||||
def clean_realm_subdomain(self):
|
def clean_realm_subdomain(self):
|
||||||
# type: () -> str
|
# type: () -> str
|
||||||
|
|||||||
@@ -9,15 +9,15 @@ from six.moves import zip
|
|||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
|
|
||||||
class JsonableError(Exception):
|
class JsonableError(Exception):
|
||||||
def __init__(self, error, status_code=400):
|
def __init__(self, msg, status_code=400):
|
||||||
self.error = error
|
self.msg = msg
|
||||||
self.status_code = status_code
|
self.status_code = status_code
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.to_json_error_msg()
|
return self.to_json_error_msg()
|
||||||
|
|
||||||
def to_json_error_msg(self):
|
def to_json_error_msg(self):
|
||||||
return self.error
|
return self.msg
|
||||||
|
|
||||||
class RequestVariableMissingError(JsonableError):
|
class RequestVariableMissingError(JsonableError):
|
||||||
def __init__(self, var_name, status_code=400):
|
def __init__(self, var_name, status_code=400):
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ from django.http import HttpResponse
|
|||||||
ViewFuncT = TypeVar('ViewFuncT', bound=Callable[..., HttpResponse])
|
ViewFuncT = TypeVar('ViewFuncT', bound=Callable[..., HttpResponse])
|
||||||
|
|
||||||
class JsonableError(Exception):
|
class JsonableError(Exception):
|
||||||
error = ... # type: Text
|
msg = ... # type: Text
|
||||||
status_code = ... # type: int
|
status_code = ... # type: int
|
||||||
def __init__(self, error: Text) -> None: ...
|
def __init__(self, msg: Text) -> None: ...
|
||||||
def to_json_error_msg(self) -> Text: ...
|
def to_json_error_msg(self) -> Text: ...
|
||||||
|
|
||||||
class RequestVariableMissingError(JsonableError): ...
|
class RequestVariableMissingError(JsonableError): ...
|
||||||
|
|||||||
@@ -643,7 +643,7 @@ class TestSendToPushBouncer(PushNotificationTest):
|
|||||||
# type: (mock.MagicMock) -> None
|
# type: (mock.MagicMock) -> None
|
||||||
with self.assertRaises(apn.JsonableError) as exc:
|
with self.assertRaises(apn.JsonableError) as exc:
|
||||||
apn.send_to_push_bouncer('register', 'register', {'data': True})
|
apn.send_to_push_bouncer('register', 'register', {'data': True})
|
||||||
self.assertEqual(exc.exception.error,
|
self.assertEqual(exc.exception.msg,
|
||||||
'Error received from push notification bouncer')
|
'Error received from push notification bouncer')
|
||||||
|
|
||||||
@mock.patch('requests.request', return_value=Result(status=400))
|
@mock.patch('requests.request', return_value=Result(status=400))
|
||||||
@@ -651,14 +651,14 @@ class TestSendToPushBouncer(PushNotificationTest):
|
|||||||
# type: (mock.MagicMock) -> None
|
# type: (mock.MagicMock) -> None
|
||||||
with self.assertRaises(apn.JsonableError) as exc:
|
with self.assertRaises(apn.JsonableError) as exc:
|
||||||
apn.send_to_push_bouncer('register', 'register', {'msg': True})
|
apn.send_to_push_bouncer('register', 'register', {'msg': True})
|
||||||
self.assertEqual(exc.exception.error, 'error')
|
self.assertEqual(exc.exception.msg, 'error')
|
||||||
|
|
||||||
@mock.patch('requests.request', return_value=Result(status=400, content='/'))
|
@mock.patch('requests.request', return_value=Result(status=400, content='/'))
|
||||||
def test_400_error_when_content_is_not_serializable(self, mock_request):
|
def test_400_error_when_content_is_not_serializable(self, mock_request):
|
||||||
# type: (mock.MagicMock) -> None
|
# type: (mock.MagicMock) -> None
|
||||||
with self.assertRaises(apn.JsonableError) as exc:
|
with self.assertRaises(apn.JsonableError) as exc:
|
||||||
apn.send_to_push_bouncer('register', 'register', {'msg': True})
|
apn.send_to_push_bouncer('register', 'register', {'msg': True})
|
||||||
self.assertEqual(exc.exception.error,
|
self.assertEqual(exc.exception.msg,
|
||||||
'Error received from push notification bouncer')
|
'Error received from push notification bouncer')
|
||||||
|
|
||||||
@mock.patch('requests.request', return_value=Result(status=300, content='/'))
|
@mock.patch('requests.request', return_value=Result(status=300, content='/'))
|
||||||
@@ -666,7 +666,7 @@ class TestSendToPushBouncer(PushNotificationTest):
|
|||||||
# type: (mock.MagicMock) -> None
|
# type: (mock.MagicMock) -> None
|
||||||
with self.assertRaises(apn.JsonableError) as exc:
|
with self.assertRaises(apn.JsonableError) as exc:
|
||||||
apn.send_to_push_bouncer('register', 'register', {'msg': True})
|
apn.send_to_push_bouncer('register', 'register', {'msg': True})
|
||||||
self.assertEqual(exc.exception.error,
|
self.assertEqual(exc.exception.msg,
|
||||||
'Error received from push notification bouncer')
|
'Error received from push notification bouncer')
|
||||||
|
|
||||||
class TestNumPushDevicesForUser(PushNotificationTest):
|
class TestNumPushDevicesForUser(PushNotificationTest):
|
||||||
|
|||||||
@@ -389,7 +389,7 @@ def json_stream_exists(request, user_profile, stream_name=REQ("stream"),
|
|||||||
(stream, recipient, sub) = access_stream_by_name(user_profile, stream_name)
|
(stream, recipient, sub) = access_stream_by_name(user_profile, stream_name)
|
||||||
except JsonableError as e:
|
except JsonableError as e:
|
||||||
result = {"exists": False}
|
result = {"exists": False}
|
||||||
return json_error(e.error, data=result, status=404)
|
return json_error(e.msg, data=result, status=404)
|
||||||
|
|
||||||
# access_stream functions return a subscription if and only if we
|
# access_stream functions return a subscription if and only if we
|
||||||
# are already subscribed.
|
# are already subscribed.
|
||||||
|
|||||||
@@ -451,7 +451,7 @@ class ZulipLDAPAuthBackend(ZulipLDAPAuthBackendBase):
|
|||||||
try:
|
try:
|
||||||
full_name = check_full_name(full_name)
|
full_name = check_full_name(full_name)
|
||||||
except JsonableError as e:
|
except JsonableError as e:
|
||||||
raise ZulipLDAPException(e.error)
|
raise ZulipLDAPException(e.msg)
|
||||||
if "short_name" in settings.AUTH_LDAP_USER_ATTR_MAP:
|
if "short_name" in settings.AUTH_LDAP_USER_ATTR_MAP:
|
||||||
short_name_attr = settings.AUTH_LDAP_USER_ATTR_MAP["short_name"]
|
short_name_attr = settings.AUTH_LDAP_USER_ATTR_MAP["short_name"]
|
||||||
short_name = ldap_user.attrs[short_name_attr][0]
|
short_name = ldap_user.attrs[short_name_attr][0]
|
||||||
|
|||||||
Reference in New Issue
Block a user