mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 14:03:30 +00:00
exceptions: Make RateLimited into a subclass of JsonableError.
This simplifies the code, as it allows using the mechanism of converting JsonableErrors into a response instead of having separate, but ultimately similar, logic in RateLimitMiddleware. We don't touch tests here because "rate limited" error responses are already verified in test_external.py.
This commit is contained in:
committed by
Alex Vandiver
parent
92ce2d0e31
commit
43a0c60e96
@@ -66,10 +66,15 @@ def json_response_from_error(exception: JsonableError) -> HttpResponse:
|
||||
middleware takes care of transforming it into a response by
|
||||
calling this function.
|
||||
'''
|
||||
return json_response('error',
|
||||
msg=exception.msg,
|
||||
data=exception.data,
|
||||
status=exception.http_status_code)
|
||||
response = json_response('error',
|
||||
msg=exception.msg,
|
||||
data=exception.data,
|
||||
status=exception.http_status_code)
|
||||
|
||||
for header, value in exception.extra_headers.items():
|
||||
response[header] = value
|
||||
|
||||
return response
|
||||
|
||||
def json_error(msg: str, data: Mapping[str, Any]={}, status: int=400) -> HttpResponse:
|
||||
return json_response(res_type="error", msg=msg, data=data, status=status)
|
||||
|
||||
Reference in New Issue
Block a user