Skip to content

Commit

Permalink
API: Fix pydantic validation errors on disconnect poll returns
Browse files Browse the repository at this point in the history
Raise a 422 exception for the disconnect. This prevents pydantic
errors when returning a "response" which doesn't contain anything
in this case.

Signed-off-by: kingbri <[email protected]>
  • Loading branch information
kingbri1 committed Jul 15, 2024
1 parent 933404c commit e20a2d5
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions common/networking.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import asyncio
import socket
import traceback
from fastapi import Request
from fastapi import HTTPException, Request
from loguru import logger
from pydantic import BaseModel
from typing import Optional
Expand Down Expand Up @@ -84,8 +84,9 @@ async def run_with_request_disconnect(

try:
return call_task.result()
except (asyncio.CancelledError, asyncio.InvalidStateError):
except (asyncio.CancelledError, asyncio.InvalidStateError) as ex:
handle_request_disconnect(disconnect_message)
raise HTTPException(422, disconnect_message) from ex


def is_port_in_use(port: int) -> bool:
Expand Down

0 comments on commit e20a2d5

Please sign in to comment.