Таска 3: разделение кастомных эксепшенов #2
@@ -7,3 +7,4 @@ from src.application.domain.exceptions.conflict_exception import ConflictExcepti
|
|||||||
from src.application.domain.exceptions.internal_exception import InternalException
|
from src.application.domain.exceptions.internal_exception import InternalException
|
||||||
from src.application.domain.exceptions.service_unavailable_exception import ServiceUnavailableException
|
from src.application.domain.exceptions.service_unavailable_exception import ServiceUnavailableException
|
||||||
from src.application.domain.exceptions.too_many_requests_exception import TooManyRequestsException
|
from src.application.domain.exceptions.too_many_requests_exception import TooManyRequestsException
|
||||||
|
from src.application.domain.exceptions.csrf_error_exception import CsrfErrorException
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
from src.application.domain.exceptions.application_exceptions import ApplicationException
|
||||||
|
|
||||||
|
from typing import Mapping
|
||||||
|
|
||||||
|
|
||||||
|
class CsrfErrorException(ApplicationException):
|
||||||
|
def __init__(self, message: str = 'CSRF context is invalid', headers: Mapping[str, str] | None = None):
|
||||||
|
super().__init__(500, message, headers)
|
||||||
@@ -3,7 +3,7 @@ import inspect
|
|||||||
from functools import wraps
|
from functools import wraps
|
||||||
from typing import Callable, Awaitable, Any, Optional, Annotated
|
from typing import Callable, Awaitable, Any, Optional, Annotated
|
||||||
from fastapi import Request, Header
|
from fastapi import Request, Header
|
||||||
from src.application.domain.exceptions import InternalException
|
from src.application.domain.exceptions import CsrfErrorException
|
||||||
from src.infrastructure.security import CsrfService
|
from src.infrastructure.security import CsrfService
|
||||||
|
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ def csrf_protect(
|
|||||||
break
|
break
|
||||||
|
|
||||||
if request is None:
|
if request is None:
|
||||||
raise InternalException(message='Request is required for CSRF protection')
|
raise CsrfErrorException(message='Request is required for CSRF protection')
|
||||||
|
|
||||||
csrf = CsrfService()
|
csrf = CsrfService()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user