forked from mtusi2026/mtusi2026lab4
Хранить вложения в приватном S3 и сверять их с PostgreSQL.
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
"""API errors mapped to the contract body. Details stay in server logs."""
|
||||
|
||||
|
||||
class ApiError(Exception):
|
||||
def __init__(self, status: int, code: str, message: str, headers: dict | None = None):
|
||||
super().__init__(message)
|
||||
self.status = status
|
||||
self.code = code
|
||||
self.message = message
|
||||
self.headers = headers or {}
|
||||
|
||||
|
||||
def unauthorized(scheme: str) -> ApiError:
|
||||
if scheme == "basic":
|
||||
challenge = 'Basic realm="messenger", charset="UTF-8"'
|
||||
else:
|
||||
challenge = 'Bearer realm="messenger"'
|
||||
return ApiError(
|
||||
401,
|
||||
"unauthorized",
|
||||
"Требуется действительная аутентификация",
|
||||
{"WWW-Authenticate": challenge},
|
||||
)
|
||||
Reference in New Issue
Block a user