Skip to content

Commit

Permalink
fix: add proper error logging for azure and openai calls (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
galkleinman authored Dec 9, 2024
1 parent 610c8fb commit 857b569
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 21 deletions.
43 changes: 32 additions & 11 deletions src/providers/azure/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,16 @@ impl Provider for AzureProvider {
.json()
.await
.map(ChatCompletionResponse::NonStream)
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)
.map_err(|e| {
eprintln!("Azure OpenAI API response error: {}", e);
StatusCode::INTERNAL_SERVER_ERROR
})
}
} else {
eprintln!(
"Azure OpenAI API request error: {}",
response.text().await.unwrap()
);
Err(StatusCode::from_u16(status.as_u16()).unwrap_or(StatusCode::INTERNAL_SERVER_ERROR))
}
}
Expand All @@ -110,15 +117,22 @@ impl Provider for AzureProvider {
.json(&payload)
.send()
.await
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
.map_err(|e| {
eprintln!("Azure OpenAI API request error: {}", e);
StatusCode::INTERNAL_SERVER_ERROR
})?;

let status = response.status();
if status.is_success() {
response
.json()
.await
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)
response.json().await.map_err(|e| {
eprintln!("Azure OpenAI API response error: {}", e);
StatusCode::INTERNAL_SERVER_ERROR
})
} else {
eprintln!(
"Azure OpenAI API request error: {}",
response.text().await.unwrap()
);
Err(StatusCode::from_u16(status.as_u16()).unwrap_or(StatusCode::INTERNAL_SERVER_ERROR))
}
}
Expand All @@ -144,15 +158,22 @@ impl Provider for AzureProvider {
.json(&payload)
.send()
.await
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
.map_err(|e| {
eprintln!("Azure OpenAI API request error: {}", e);
StatusCode::INTERNAL_SERVER_ERROR
})?;

let status = response.status();
if status.is_success() {
response
.json()
.await
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)
response.json().await.map_err(|e| {
eprintln!("Azure OpenAI API response error: {}", e);
StatusCode::INTERNAL_SERVER_ERROR
})
} else {
eprintln!(
"Azure OpenAI API request error: {}",
response.text().await.unwrap()
);
Err(StatusCode::from_u16(status.as_u16()).unwrap_or(StatusCode::INTERNAL_SERVER_ERROR))
}
}
Expand Down
34 changes: 24 additions & 10 deletions src/providers/openai/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,22 @@ impl Provider for OpenAIProvider {
.json(&payload)
.send()
.await
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
.map_err(|e| {
eprintln!("OpenAI API request error: {}", e);
StatusCode::INTERNAL_SERVER_ERROR
})?;

let status = response.status();
if status.is_success() {
response
.json()
.await
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)
response.json().await.map_err(|e| {
eprintln!("OpenAI API response error: {}", e);
StatusCode::INTERNAL_SERVER_ERROR
})
} else {
eprintln!(
"OpenAI API request error: {}",
response.text().await.unwrap()
);
Err(StatusCode::from_u16(status.as_u16()).unwrap_or(StatusCode::INTERNAL_SERVER_ERROR))
}
}
Expand All @@ -111,15 +118,22 @@ impl Provider for OpenAIProvider {
.json(&payload)
.send()
.await
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
.map_err(|e| {
eprintln!("OpenAI API request error: {}", e);
StatusCode::INTERNAL_SERVER_ERROR
})?;

let status = response.status();
if status.is_success() {
response
.json()
.await
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)
response.json().await.map_err(|e| {
eprintln!("OpenAI API response error: {}", e);
StatusCode::INTERNAL_SERVER_ERROR
})
} else {
eprintln!(
"OpenAI API request error: {}",
response.text().await.unwrap()
);
Err(StatusCode::from_u16(status.as_u16()).unwrap_or(StatusCode::INTERNAL_SERVER_ERROR))
}
}
Expand Down

0 comments on commit 857b569

Please sign in to comment.