Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 24 additions & 17 deletions crates/goose/src/providers/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,33 +68,32 @@ pub fn map_http_error_to_provider_error(
status: StatusCode,
payload: Option<Value>,
) -> ProviderError {
match status {
let error = match status {
StatusCode::OK => unreachable!("Should not call this function with OK status"),
StatusCode::UNAUTHORIZED | StatusCode::FORBIDDEN => {
ProviderError::Authentication(format!(
"Authentication failed. Please ensure your API keys are valid and have the required permissions. \
Status: {}. Response: {:?}", status, payload
Status: {}. Response: {:?}", status, payload
))
}
StatusCode::BAD_REQUEST => {
let mut error_msg = "Unknown error".to_string();
if let Some(payload) = &payload {
let payload_str = payload.to_string();
if check_context_length_exceeded(&payload_str) {
return ProviderError::ContextLengthExceeded(payload_str);
}

if let Some(error) = payload.get("error") {
error_msg = error.get("message")
.and_then(|m| m.as_str())
.unwrap_or("Unknown error")
.to_string();
ProviderError::ContextLengthExceeded(payload_str)
} else {
if let Some(error) = payload.get("error") {
error_msg = error.get("message")
.and_then(|m| m.as_str())
.unwrap_or("Unknown error")
.to_string();
}
ProviderError::RequestFailed(format!("Request failed with status: {}. Message: {}", status, error_msg))
}
} else {
ProviderError::RequestFailed(format!("Request failed with status: {}. Message: {}", status, error_msg))
}
tracing::debug!(
"Provider request failed with status: {}. Payload: {:?}", status, payload
);
ProviderError::RequestFailed(format!("Request failed with status: {}. Message: {}", status, error_msg))
}
StatusCode::TOO_MANY_REQUESTS => {
ProviderError::RateLimitExceeded(format!("{:?}", payload))
Expand All @@ -103,12 +102,20 @@ pub fn map_http_error_to_provider_error(
ProviderError::ServerError(format!("{:?}", payload))
}
_ => {
tracing::debug!(
"Provider request failed with status: {}. Payload: {:?}", status, payload
);
ProviderError::RequestFailed(format!("Request failed with status: {}", status))
}
};

if !status.is_success() {
tracing::warn!(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do warns make it to the log file?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, or at least I saw them

"Provider request failed with status: {}. Payload: {:?}. Returning error: {:?}",
status,
payload,
error
);
}

error
}

/// Handle response from OpenAI compatible endpoints
Expand Down
Loading
Loading