mirror of
https://github.com/open-webui/open-webui
synced 2024-11-16 13:40:55 +00:00
refac: error handling
This commit is contained in:
parent
e5cfa6501b
commit
8f6369374d
@ -739,10 +739,16 @@ class PipelineMiddleware(BaseHTTPMiddleware):
|
|||||||
try:
|
try:
|
||||||
data = filter_pipeline(data, user)
|
data = filter_pipeline(data, user)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return JSONResponse(
|
if len(e.args) > 1:
|
||||||
status_code=e.args[0],
|
return JSONResponse(
|
||||||
content={"detail": e.args[1]},
|
status_code=e.args[0],
|
||||||
)
|
content={"detail": e.args[1]},
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
return JSONResponse(
|
||||||
|
status_code=status.HTTP_400_BAD_REQUEST,
|
||||||
|
content={"detail": str(e)},
|
||||||
|
)
|
||||||
|
|
||||||
modified_body_bytes = json.dumps(data).encode("utf-8")
|
modified_body_bytes = json.dumps(data).encode("utf-8")
|
||||||
# Replace the request body with the modified one
|
# Replace the request body with the modified one
|
||||||
@ -1390,10 +1396,16 @@ async def generate_title(form_data: dict, user=Depends(get_verified_user)):
|
|||||||
try:
|
try:
|
||||||
payload = filter_pipeline(payload, user)
|
payload = filter_pipeline(payload, user)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return JSONResponse(
|
if len(e.args) > 1:
|
||||||
status_code=e.args[0],
|
return JSONResponse(
|
||||||
content={"detail": e.args[1]},
|
status_code=e.args[0],
|
||||||
)
|
content={"detail": e.args[1]},
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
return JSONResponse(
|
||||||
|
status_code=status.HTTP_400_BAD_REQUEST,
|
||||||
|
content={"detail": str(e)},
|
||||||
|
)
|
||||||
|
|
||||||
if "chat_id" in payload:
|
if "chat_id" in payload:
|
||||||
del payload["chat_id"]
|
del payload["chat_id"]
|
||||||
@ -1443,10 +1455,16 @@ async def generate_search_query(form_data: dict, user=Depends(get_verified_user)
|
|||||||
try:
|
try:
|
||||||
payload = filter_pipeline(payload, user)
|
payload = filter_pipeline(payload, user)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return JSONResponse(
|
if len(e.args) > 1:
|
||||||
status_code=e.args[0],
|
return JSONResponse(
|
||||||
content={"detail": e.args[1]},
|
status_code=e.args[0],
|
||||||
)
|
content={"detail": e.args[1]},
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
return JSONResponse(
|
||||||
|
status_code=status.HTTP_400_BAD_REQUEST,
|
||||||
|
content={"detail": str(e)},
|
||||||
|
)
|
||||||
|
|
||||||
if "chat_id" in payload:
|
if "chat_id" in payload:
|
||||||
del payload["chat_id"]
|
del payload["chat_id"]
|
||||||
@ -1500,10 +1518,16 @@ Message: """{{prompt}}"""
|
|||||||
try:
|
try:
|
||||||
payload = filter_pipeline(payload, user)
|
payload = filter_pipeline(payload, user)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return JSONResponse(
|
if len(e.args) > 1:
|
||||||
status_code=e.args[0],
|
return JSONResponse(
|
||||||
content={"detail": e.args[1]},
|
status_code=e.args[0],
|
||||||
)
|
content={"detail": e.args[1]},
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
return JSONResponse(
|
||||||
|
status_code=status.HTTP_400_BAD_REQUEST,
|
||||||
|
content={"detail": str(e)},
|
||||||
|
)
|
||||||
|
|
||||||
if "chat_id" in payload:
|
if "chat_id" in payload:
|
||||||
del payload["chat_id"]
|
del payload["chat_id"]
|
||||||
@ -1552,10 +1576,16 @@ Responses from models: {{responses}}"""
|
|||||||
try:
|
try:
|
||||||
payload = filter_pipeline(payload, user)
|
payload = filter_pipeline(payload, user)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return JSONResponse(
|
if len(e.args) > 1:
|
||||||
status_code=e.args[0],
|
return JSONResponse(
|
||||||
content={"detail": e.args[1]},
|
status_code=e.args[0],
|
||||||
)
|
content={"detail": e.args[1]},
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
return JSONResponse(
|
||||||
|
status_code=status.HTTP_400_BAD_REQUEST,
|
||||||
|
content={"detail": str(e)},
|
||||||
|
)
|
||||||
|
|
||||||
if "chat_id" in payload:
|
if "chat_id" in payload:
|
||||||
del payload["chat_id"]
|
del payload["chat_id"]
|
||||||
|
Loading…
Reference in New Issue
Block a user