handle ClientDisconnect for http and websocket

This commit is contained in:
henryruhs committed 2026-09-23 15:00:33 +02:00
1 parent e43a5be98b
commit b99f8e00bd
1 file changed
+10 -1
+10 -1
View File
@@ -4,6 +4,7 @@ from starlette.requests import ClientDisconnect
from starlette.responses import JSONResponse
from starlette.status import HTTP_400_BAD_REQUEST
from starlette.types import ASGIApp, Receive, Scope, Send
from starlette.websockets import WebSocketDisconnect
from facefusion import translator
@@ -13,13 +14,21 @@ def create_exception_guard(app : ASGIApp) -> ASGIApp:
if scope.get('type') == 'http':
try:
return await app(scope, receive, send)
except (ClientDisconnect, JSONDecodeError, UnicodeDecodeError):
except (JSONDecodeError, UnicodeDecodeError):
response = JSONResponse(
{
'message': translator.get('something_went_wrong', 'facefusion.apis')
}, status_code = HTTP_400_BAD_REQUEST)
return await response(scope, receive, send)
except ClientDisconnect:
return
if scope.get('type') == 'websocket':
try:
return await app(scope, receive, send)
except WebSocketDisconnect:
return
return await app(scope, receive, send)