fix critical http error
This commit is contained in:
parent
d25d1bb8b3
commit
d3678cb150
@ -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:
|
||||||
|
if with_httpexception:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=response.status_code,
|
status_code=response.status_code,
|
||||||
detail=f"chat_private_service: {response.text}"
|
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:
|
||||||
|
if with_httpexception:
|
||||||
raise HTTPException(status_code=status.HTTP_503_SERVICE_UNAVAILABLE, detail=f"chat_private_service unreachable: {str(e)}")
|
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)}"
|
||||||
|
|||||||
@ -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"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user