forked from mtusi2026/mtusi2026lab5
formatted project by python-black
This commit is contained in:
@@ -90,14 +90,23 @@ def internal_error() -> ApiError:
|
||||
|
||||
|
||||
IMAGE_WORKER_ERRORS = (
|
||||
ApiError, Image.DecompressionBombError, Image.DecompressionBombWarning,
|
||||
MemoryError, UnidentifiedImageError, OSError, ValueError, SyntaxError,
|
||||
ApiError,
|
||||
Image.DecompressionBombError,
|
||||
Image.DecompressionBombWarning,
|
||||
MemoryError,
|
||||
UnidentifiedImageError,
|
||||
OSError,
|
||||
ValueError,
|
||||
SyntaxError,
|
||||
)
|
||||
|
||||
|
||||
def image_worker_error_code(error: Exception) -> int:
|
||||
code = 2
|
||||
resource_error = isinstance(error, (Image.DecompressionBombError, Image.DecompressionBombWarning, MemoryError))
|
||||
resource_error = isinstance(
|
||||
error,
|
||||
(Image.DecompressionBombError, Image.DecompressionBombWarning, MemoryError),
|
||||
)
|
||||
declared_limit = isinstance(error, ApiError) and error.status_code == 413
|
||||
if resource_error or declared_limit:
|
||||
code = 3
|
||||
|
||||
+17
-4
@@ -18,14 +18,25 @@ from urllib3.exceptions import HTTPError as StorageHTTPError
|
||||
|
||||
from app.core.instance import INSTANCE_ID_HEADER
|
||||
from app.core.request_id import REQUEST_ID_HEADER
|
||||
from app.errors.exceptions import ApiError, internal_error, invalid_request, not_found, unavailable
|
||||
from app.errors.exceptions import (
|
||||
ApiError,
|
||||
internal_error,
|
||||
invalid_request,
|
||||
not_found,
|
||||
unavailable,
|
||||
)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
TRANSIENT_SQLSTATE_CLASSES = ("08", "40", "53", "57")
|
||||
TRANSIENT_SQLSTATES = frozenset({"55P03"})
|
||||
RECOVERABLE_STORAGE_ERRORS = (
|
||||
ApiError, SQLAlchemyError, MinioException, StorageHTTPError, OSError, TimeoutError,
|
||||
ApiError,
|
||||
SQLAlchemyError,
|
||||
MinioException,
|
||||
StorageHTTPError,
|
||||
OSError,
|
||||
TimeoutError,
|
||||
)
|
||||
|
||||
|
||||
@@ -40,12 +51,14 @@ async def operation_timeout(seconds: float, error: ApiError):
|
||||
|
||||
|
||||
async def client_disconnect_handler(request: Request, exc: Exception) -> JSONResponse:
|
||||
return await api_error_handler(request, invalid_request("Загрузка прервана клиентом"))
|
||||
return await api_error_handler(
|
||||
request, invalid_request("Загрузка прервана клиентом")
|
||||
)
|
||||
|
||||
|
||||
def log_recoverable_error(operation: str, error: Exception) -> None:
|
||||
"""Согласованный безопасный лог восстановления без содержимого SDK-ошибки."""
|
||||
logger.warning('%s deferred: %s', operation, type(error).__name__)
|
||||
logger.warning("%s deferred: %s", operation, type(error).__name__)
|
||||
|
||||
|
||||
def _get_request_id(request: Request) -> str:
|
||||
|
||||
Reference in New Issue
Block a user