fix critical http error

This commit is contained in:
unknown 2025-10-20 23:04:16 +03:00
parent d25d1bb8b3
commit d3678cb150
2 changed files with 17 additions and 8 deletions

View File

@ -5,7 +5,12 @@ from config import settings
from common_lib.utils.http_client import client from common_lib.utils.http_client import client
async def send_internal_message(sender: str, user_id: UUID, content: str) -> dict: async def send_internal_message(
sender: str,
user_id: UUID,
content: str,
with_httpexception = False
) -> dict:
try: try:
response = await client.post( response = await client.post(
f"{settings.CHAT_PRIVATE_SERVICE}/internal/send", f"{settings.CHAT_PRIVATE_SERVICE}/internal/send",
@ -15,13 +20,17 @@ async def send_internal_message(sender: str, user_id: UUID, content: str) -> dic
}) })
if response.status_code != 200: if response.status_code != 200:
raise HTTPException( if with_httpexception:
status_code=response.status_code, raise HTTPException(
detail=f"chat_private_service: {response.text}" status_code=response.status_code,
) detail=f"chat_private_service: {response.text}"
)
return response.status_code, f"chat_private_service: {response.text}"
wrapped = response.json() wrapped = response.json()
return wrapped["data"] return 200, wrapped
except httpx.RequestError as e: except httpx.RequestError as e:
raise HTTPException(status_code=status.HTTP_503_SERVICE_UNAVAILABLE, detail=f"chat_private_service unreachable: {str(e)}") if with_httpexception:
raise HTTPException(status_code=status.HTTP_503_SERVICE_UNAVAILABLE, detail=f"chat_private_service unreachable: {str(e)}")
return 503, f"chat_private_service unreachable: {str(e)}"

View File

@ -1,6 +1,6 @@
[project] [project]
name = "common-lib" name = "common-lib"
version = "0.0.28" version = "0.0.29"
description = "Библиотека общих компонентов для микросервисов yobble" description = "Библиотека общих компонентов для микросервисов yobble"
authors = [{ name = "cheykrym", email = "you@example.com" }] authors = [{ name = "cheykrym", email = "you@example.com" }]
license = "MIT" license = "MIT"