fix: log raw embedding response before parsing for debugging
- Read response as text first, then parse JSON - Log raw body on parse failure (up to 500 chars) - Log status code + body on non-2xx responses - Helps diagnose 'expected ident at line 1 column 2' error
This commit is contained in:
@@ -166,8 +166,18 @@ impl EmbeddingsClient {
|
||||
}
|
||||
|
||||
let resp = builder.json(&req).send().await?;
|
||||
let _status = resp.status();
|
||||
let body: EmbeddingResponse = resp.json().await?;
|
||||
let status = resp.status();
|
||||
let raw_body = resp.text().await?;
|
||||
|
||||
if !status.is_success() {
|
||||
tracing::error!("Embedding API returned {}: {}", status, &raw_body[..raw_body.len().min(500)]);
|
||||
return Err(anyhow!("Embedding API returned {}: {}", status, &raw_body[..raw_body.len().min(200)]));
|
||||
}
|
||||
|
||||
let body: EmbeddingResponse = serde_json::from_str(&raw_body).map_err(|e| {
|
||||
tracing::error!("Failed to parse embedding response: {}. Raw body: {}", e, &raw_body[..raw_body.len().min(500)]);
|
||||
anyhow!("Failed to parse embedding response: {}. Raw: {}", e, &raw_body[..raw_body.len().min(200)])
|
||||
})?;
|
||||
|
||||
match body {
|
||||
EmbeddingResponse::Error { error } => {
|
||||
|
||||
Reference in New Issue
Block a user