Skip to content

Commit 4292358

Browse files
authored
feat: log provider errors to console for better insights (open-webui#23379)
* fix: log provider errors that were silently swallowed * Update main.py * fix: wrap non-JSON SSE error responses in JSON so middleware handles them
1 parent 6702303 commit 4292358

3 files changed

Lines changed: 23 additions & 1 deletion

File tree

backend/open_webui/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1797,7 +1797,7 @@ async def process_chat(request, form_data, user, metadata, model):
17971797
finally:
17981798
raise # re-raise to ensure proper task cancellation handling
17991799
except Exception as e:
1800-
log.debug(f'Error processing chat payload: {e}')
1800+
log.error('Error processing chat payload: %s', e)
18011801
if metadata.get('chat_id') and metadata.get('message_id'):
18021802
# Update the chat message with the error
18031803
try:

backend/open_webui/routers/openai.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,6 +1195,25 @@ async def generate_chat_completion(
11951195

11961196
# Check if response is SSE
11971197
if 'text/event-stream' in r.headers.get('Content-Type', ''):
1198+
# If the provider returned an error status with SSE content-type,
1199+
# read the body and return a proper error response instead of
1200+
# streaming the error back (which hides the error from logs).
1201+
if r.status >= 400:
1202+
error_body = await r.text()
1203+
log.error(
1204+
'Provider returned HTTP %d with SSE content-type: %s',
1205+
r.status,
1206+
error_body[:1000],
1207+
)
1208+
try:
1209+
error_json = json.loads(error_body)
1210+
return JSONResponse(status_code=r.status, content=error_json)
1211+
except json.JSONDecodeError:
1212+
return JSONResponse(
1213+
status_code=r.status,
1214+
content={"error": {"message": error_body, "code": r.status}},
1215+
)
1216+
11981217
streaming = True
11991218
return StreamingResponse(
12001219
stream_wrapper(r, content_handler=stream_chunks_handler),

backend/open_webui/utils/middleware.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3077,6 +3077,8 @@ async def non_streaming_chat_response_handler(response, ctx):
30773077
else:
30783078
error = str(error)
30793079

3080+
log.error('Provider returned error (non-streaming): %s', error)
3081+
30803082
await Chats.upsert_message_to_chat_by_id_and_message_id(
30813083
metadata['chat_id'],
30823084
metadata['message_id'],
@@ -3645,6 +3647,7 @@ async def flush_pending_delta_data(threshold: int = 0):
36453647
if not choices:
36463648
error = data.get('error', {})
36473649
if error:
3650+
log.error('Provider returned error (streaming): %s', error)
36483651
try:
36493652
await Chats.upsert_message_to_chat_by_id_and_message_id(
36503653
metadata['chat_id'],

0 commit comments

Comments
 (0)