Skip to content

Commit c3e1d2d

Browse files
committed
refac
1 parent 0bfacca commit c3e1d2d

1 file changed

Lines changed: 27 additions & 2 deletions

File tree

backend/open_webui/routers/audio.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -852,17 +852,36 @@ def transcription_handler(request, file_path, metadata, user=None):
852852
except requests.exceptions.RequestException as e:
853853
log.exception(e)
854854
detail = None
855+
status_code = getattr(r, "status_code", 500) if r else 500
855856

856857
try:
857858
if r is not None and r.status_code != 200:
858859
res = r.json()
859-
if "error" in res:
860+
# Azure returns {"code": "...", "message": "...", "innerError": {...}}
861+
if "code" in res and "message" in res:
862+
azure_code = res.get("innerError", {}).get(
863+
"code", res["code"]
864+
)
865+
user_facing_codes = {
866+
"EmptyAudioFile",
867+
"AudioLengthLimitExceeded",
868+
"NoLanguageIdentified",
869+
"MultipleLanguagesIdentified",
870+
}
871+
if azure_code in user_facing_codes:
872+
detail = res["message"]
873+
else:
874+
log.error(
875+
f"Azure STT error [{azure_code}]: {res['message']}"
876+
)
877+
detail = "An error occurred during transcription."
878+
elif "error" in res:
860879
detail = f"External: {res['error'].get('message', '')}"
861880
except Exception:
862881
detail = f"External: {e}"
863882

864883
raise HTTPException(
865-
status_code=getattr(r, "status_code", 500) if r else 500,
884+
status_code=status_code,
866885
detail=detail if detail else "Open WebUI: Server Connection Error",
867886
)
868887

@@ -1087,6 +1106,8 @@ def transcribe(
10871106
for future in futures:
10881107
try:
10891108
results.append(future.result())
1109+
except HTTPException:
1110+
raise
10901111
except Exception as transcribe_exc:
10911112
raise HTTPException(
10921113
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
@@ -1226,6 +1247,8 @@ def transcription(
12261247
"filename": os.path.basename(file_path),
12271248
}
12281249

1250+
except HTTPException:
1251+
raise
12291252
except Exception as e:
12301253
log.exception(e)
12311254

@@ -1234,6 +1257,8 @@ def transcription(
12341257
detail="Transcription failed.",
12351258
)
12361259

1260+
except HTTPException:
1261+
raise
12371262
except Exception as e:
12381263
log.exception(e)
12391264

0 commit comments

Comments
 (0)