fix: propagate warmup errors and skip when no API key configured
Address review feedback from @coderabbitai and @gemini-code-assist: - Missing API key is now a silent no-op instead of returning an error - Network/TLS errors are now propagated via `?` instead of silently discarded, so they surface as non-fatal warnings in the caller's log - Added `error_for_status()` to catch HTTP-level failures Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
cc13fec16d
commit
1110158b23
1 changed files with 8 additions and 10 deletions
|
|
@ -54,16 +54,14 @@ impl Provider for OpenRouterProvider {
|
|||
async fn warmup(&self) -> anyhow::Result<()> {
|
||||
// Hit a lightweight endpoint to establish TLS + HTTP/2 connection pool.
|
||||
// This prevents the first real chat request from timing out on cold start.
|
||||
let api_key = self
|
||||
.api_key
|
||||
.as_ref()
|
||||
.ok_or_else(|| anyhow::anyhow!("No API key for warmup"))?;
|
||||
let _ = self
|
||||
.client
|
||||
.get("https://openrouter.ai/api/v1/auth/key")
|
||||
.header("Authorization", format!("Bearer {api_key}"))
|
||||
.send()
|
||||
.await;
|
||||
if let Some(api_key) = self.api_key.as_ref() {
|
||||
self.client
|
||||
.get("https://openrouter.ai/api/v1/auth/key")
|
||||
.header("Authorization", format!("Bearer {api_key}"))
|
||||
.send()
|
||||
.await?
|
||||
.error_for_status()?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue