fix: handle qwen rerank error response (#15881)

### What problem does this PR solve?
Fix QWen rerank error handling so DashScope error responses without a
text attribute do not raise a secondary KeyError and hide the real
provider error.

### Type of change
- [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
buua436
2026-06-10 13:05:24 +08:00
committed by GitHub
parent 9aa81e7cad
commit 093eec3105

View File

@@ -432,7 +432,16 @@ class QWenRerank(Base):
log_exception(_e, resp)
return rank, total_token_count_from_response(resp)
else:
raise ValueError(f"Error calling QWenRerank model {self.model_name}: {resp.status_code} - {resp.text}")
try:
error_body = resp["text"] if isinstance(resp, dict) and "text" in resp else None
except Exception:
error_body = None
if not error_body:
try:
error_body = json.dumps(dict(resp), ensure_ascii=False)
except Exception:
error_body = str(resp)
raise ValueError(f"Error calling QWenRerank model {self.model_name}: {resp.status_code} - {error_body}")
class HuggingfaceRerank(Base):