forked from mtusi2026/mtusi2026lab3
fix: добавить заголовок WWW-Authenticate в ответы 401
Co-authored-by: aider (deepseek/deepseek-chat) <aider@aider.chat>
This commit is contained in:
@@ -11,7 +11,14 @@ class ApiError(Exception):
|
||||
|
||||
def error_response(request: Request, status: int, code: str, message: str) -> JSONResponse:
|
||||
rid = getattr(request.state, "request_id", "")
|
||||
headers = {}
|
||||
if status == 401:
|
||||
if request.url.path == "/api/v1/auth/sessions":
|
||||
headers["WWW-Authenticate"] = 'Basic realm="messenger", charset="UTF-8"'
|
||||
else:
|
||||
headers["WWW-Authenticate"] = 'Bearer realm="messenger"'
|
||||
return JSONResponse(
|
||||
status_code=status,
|
||||
content={"error": {"code": code, "message": message, "request_id": rid}},
|
||||
headers=headers,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user