mirror of
https://github.com/open-webui/open-webui
synced 2025-06-26 18:26:48 +00:00
refac: pass through ollama error message
This commit is contained in:
parent
61d8d2f2cb
commit
e46e87889e
@ -147,8 +147,23 @@ async def send_post_request(
|
|||||||
},
|
},
|
||||||
ssl=AIOHTTP_CLIENT_SESSION_SSL,
|
ssl=AIOHTTP_CLIENT_SESSION_SSL,
|
||||||
)
|
)
|
||||||
r.raise_for_status()
|
|
||||||
|
|
||||||
|
if r.ok is False:
|
||||||
|
try:
|
||||||
|
res = await r.json()
|
||||||
|
if "error" in res:
|
||||||
|
log.error(f"Error from server: {res['error']}")
|
||||||
|
raise HTTPException(status_code=r.status, detail=res["error"])
|
||||||
|
except HTTPException as e:
|
||||||
|
raise e # Re-raise HTTPException to be handled by FastAPI
|
||||||
|
except Exception as e:
|
||||||
|
log.error(f"Failed to parse error response: {e}")
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=r.status,
|
||||||
|
detail=f"Open WebUI: Server Connection Error",
|
||||||
|
)
|
||||||
|
|
||||||
|
r.raise_for_status() # Raises an error for bad responses (4xx, 5xx)
|
||||||
if stream:
|
if stream:
|
||||||
response_headers = dict(r.headers)
|
response_headers = dict(r.headers)
|
||||||
|
|
||||||
@ -168,20 +183,14 @@ async def send_post_request(
|
|||||||
await cleanup_response(r, session)
|
await cleanup_response(r, session)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
except HTTPException as e:
|
||||||
|
raise e # Re-raise HTTPException to be handled by FastAPI
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
detail = None
|
detail = f"Ollama: {e}"
|
||||||
|
|
||||||
if r is not None:
|
|
||||||
try:
|
|
||||||
res = await r.json()
|
|
||||||
if "error" in res:
|
|
||||||
detail = f"Ollama: {res.get('error', 'Unknown error')}"
|
|
||||||
except Exception:
|
|
||||||
detail = f"Ollama: {e}"
|
|
||||||
|
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=r.status if r else 500,
|
status_code=r.status if r else 500,
|
||||||
detail=detail if detail else "Open WebUI: Server Connection Error",
|
detail=detail if e else "Open WebUI: Server Connection Error",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user