mirror of
https://github.com/facefusion/facefusion.git
synced 2026-11-12 05:19:57 +01:00
improve exception guard
This commit is contained in:
1 parent
4fb325abd2
commit
5e6eaad1dd
1 file changed
+11
-8
@@ -10,14 +10,17 @@ from facefusion import translator
|
||||
|
||||
def create_exception_guard(app : ASGIApp) -> ASGIApp:
|
||||
async def middleware(scope : Scope, receive : Receive, send : Send) -> None:
|
||||
try:
|
||||
await app(scope, receive, send)
|
||||
except (ClientDisconnect, JSONDecodeError):
|
||||
response = JSONResponse(
|
||||
{
|
||||
'message': translator.get('something_went_wrong', 'facefusion.apis')
|
||||
}, status_code = HTTP_400_BAD_REQUEST)
|
||||
if scope.get('type') == 'http':
|
||||
try:
|
||||
return await app(scope, receive, send)
|
||||
except (ClientDisconnect, JSONDecodeError, UnicodeDecodeError):
|
||||
response = JSONResponse(
|
||||
{
|
||||
'message': translator.get('something_went_wrong', 'facefusion.apis')
|
||||
}, status_code = HTTP_400_BAD_REQUEST)
|
||||
|
||||
await response(scope, receive, send)
|
||||
return await response(scope, receive, send)
|
||||
|
||||
return await app(scope, receive, send)
|
||||
|
||||
return middleware
|
||||
Reference in new issue
Block a user