forked from mtusi2026/mtusi2026lab4
Implement lab4 attachments on RustFS for grade 4.
Carry over lab3 HA stack and add private S3 storage, Attachment API, orphan compensation/reaper, own tests, and evidence for smoke/persistence/failover.
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
"""Единый формат ошибок API."""
|
||||
from typing import Optional
|
||||
|
||||
|
||||
class AppError(Exception):
|
||||
def __init__(
|
||||
self,
|
||||
status: int,
|
||||
code: str,
|
||||
message: str,
|
||||
headers: Optional[dict] = None,
|
||||
) -> None:
|
||||
self.status = status
|
||||
self.code = code
|
||||
self.message = message
|
||||
self.headers = headers or {}
|
||||
super().__init__(message)
|
||||
|
||||
|
||||
def invalid_request(message: str = "Неверный запрос") -> AppError:
|
||||
return AppError(400, "invalid_request", message)
|
||||
|
||||
|
||||
def unauthorized(
|
||||
message: str = "Требуется идентификация",
|
||||
*,
|
||||
challenge: str = 'Bearer realm="messenger"',
|
||||
) -> AppError:
|
||||
return AppError(
|
||||
401,
|
||||
"unauthorized",
|
||||
message,
|
||||
headers={"WWW-Authenticate": challenge},
|
||||
)
|
||||
|
||||
|
||||
def not_found(message: str = "Объект не найден") -> AppError:
|
||||
return AppError(404, "not_found", message)
|
||||
|
||||
|
||||
def conflict(message: str = "Конфликт") -> AppError:
|
||||
return AppError(409, "conflict", message)
|
||||
|
||||
|
||||
def unsupported_media(message: str = "Неподдерживаемый Content-Type") -> AppError:
|
||||
return AppError(415, "unsupported_media_type", message)
|
||||
|
||||
|
||||
def payload_too_large(message: str = "Слишком большой файл") -> AppError:
|
||||
return AppError(413, "payload_too_large", message)
|
||||
|
||||
|
||||
def unavailable(message: str = "Сервис недоступен") -> AppError:
|
||||
return AppError(503, "unavailable", message)
|
||||
|
||||
|
||||
def error_body(code: str, message: str, request_id: str) -> dict:
|
||||
return {"error": {"code": code, "message": message, "request_id": request_id}}
|
||||
Reference in New Issue
Block a user