mirror of
https://github.com/zulip/zulip.git
synced 2025-11-08 16:01:58 +00:00
exceptions: RateLimited shouldn't inherit from PermissionDenied.
We will want to raise RateLimited in authenticate() in rate limiting code - Django's authenticate() mechanism catches PermissionDenied, which we don't want for RateLimited. We want RateLimited to propagate to our code that called the authenticate() function.
This commit is contained in:
committed by
Tim Abbott
parent
a6a2d70320
commit
335b804510
@@ -2,7 +2,6 @@ from enum import Enum
|
|||||||
from typing import Any, Dict, List, Type, TypeVar, Optional
|
from typing import Any, Dict, List, Type, TypeVar, Optional
|
||||||
from typing_extensions import NoReturn
|
from typing_extensions import NoReturn
|
||||||
|
|
||||||
from django.core.exceptions import PermissionDenied
|
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
|
|
||||||
|
|
||||||
@@ -179,7 +178,7 @@ class InvalidMarkdownIncludeStatement(JsonableError):
|
|||||||
def msg_format() -> str:
|
def msg_format() -> str:
|
||||||
return _("Invalid markdown include statement: {include_statement}")
|
return _("Invalid markdown include statement: {include_statement}")
|
||||||
|
|
||||||
class RateLimited(PermissionDenied):
|
class RateLimited(Exception):
|
||||||
def __init__(self, msg: str="") -> None:
|
def __init__(self, msg: str="") -> None:
|
||||||
super().__init__(msg)
|
super().__init__(msg)
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,7 @@ import logging
|
|||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
from typing import Any, AnyStr, Dict, \
|
from typing import Any, AnyStr, Dict, \
|
||||||
Iterable, List, MutableMapping, Optional, \
|
Iterable, List, MutableMapping, Optional
|
||||||
Union
|
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.sessions.backends.base import UpdateError
|
from django.contrib.sessions.backends.base import UpdateError
|
||||||
@@ -350,12 +349,8 @@ class RateLimitMiddleware(MiddlewareMixin):
|
|||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
# TODO: When we have Django stubs, we should be able to fix the
|
|
||||||
# type of exception back to just Exception; the problem is without
|
|
||||||
# stubs, mypy doesn't know that RateLimited's superclass
|
|
||||||
# PermissionDenied inherits from Exception.
|
|
||||||
def process_exception(self, request: HttpRequest,
|
def process_exception(self, request: HttpRequest,
|
||||||
exception: Union[Exception, RateLimited]) -> Optional[HttpResponse]:
|
exception: Exception) -> Optional[HttpResponse]:
|
||||||
if isinstance(exception, RateLimited):
|
if isinstance(exception, RateLimited):
|
||||||
entity_type = str(exception) # entity type is passed to RateLimited when raising
|
entity_type = str(exception) # entity type is passed to RateLimited when raising
|
||||||
resp = json_error(
|
resp = json_error(
|
||||||
|
|||||||
Reference in New Issue
Block a user