Skip to content

Commit

Permalink
fix: ignore payload in the CLI output if provider has error (#697)
Browse files Browse the repository at this point in the history
  • Loading branch information
yingjiehe-xyz authored Jan 23, 2025
1 parent d69b527 commit c95c8a4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
11 changes: 2 additions & 9 deletions crates/goose/src/providers/anthropic.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use anyhow::Result;
use async_trait::async_trait;
use reqwest::Client;
use reqwest::StatusCode;
use serde_json::Value;
use std::time::Duration;

use super::base::{Provider, ProviderUsage, Usage};
use super::configs::ModelConfig;
use super::formats::anthropic::{create_request, get_usage, response_to_message};
use super::utils::{emit_debug_trace, get_model, non_ok_response_to_provider_error};
use super::utils::{emit_debug_trace, get_model, handle_response};
use crate::message::Message;
use mcp_core::tool::Tool;

Expand Down Expand Up @@ -56,13 +55,7 @@ impl AnthropicProvider {
.send()
.await?;

match response.status() {
StatusCode::OK => Ok(response.json().await?),
_ => {
let provider_error = non_ok_response_to_provider_error(payload, response).await;
Err(anyhow::anyhow!(provider_error.to_string()))
}
}
handle_response(payload, response).await
}
}

Expand Down
7 changes: 6 additions & 1 deletion crates/goose/src/providers/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ pub async fn non_ok_response_to_provider_error(
StatusCode::INTERNAL_SERVER_ERROR | StatusCode::SERVICE_UNAVAILABLE => {
ProviderError::ServerError(format!("Server error occurred. Status: {}", response.status()))
}
_ => ProviderError::RequestFailed(format!("Request failed with status: {}. Payload: {}", response.status(), payload))
_ => {
tracing::debug!(
"{}", format!("Provider request failed with status: {}. Payload: {}", response.status(), payload)
);
ProviderError::RequestFailed(format!("Request failed with status: {}.", response.status()))
}
}
}

Expand Down

0 comments on commit c95c8a4

Please sign in to comment.