mirror of
https://github.com/block/goose.git
synced 2026-07-17 12:56:20 +02:00
fix: improve server error messages to include HTTP status code
Fixes #5528 Previously, when a server error (5xx) occurred without a response body, the error message would display 'Server error: None', which was not helpful for debugging. This change improves error messages by: - Including the HTTP status code (e.g., 'HTTP 500') - Providing a clear message when no response body is received - Maintaining detailed error info when a response body is present Example error messages: - Before: 'Server error: None' - After: 'HTTP 500: No response body received from server' This affects all OpenAI-compatible providers (OpenAI, Claude, Google, Ollama, Azure, Databricks, GitHub Copilot, etc.) and Google-compatible endpoints.
This commit is contained in:
@@ -116,7 +116,17 @@ pub fn map_http_error_to_provider_error(
|
||||
details: format!("{:?}", payload),
|
||||
retry_delay: None,
|
||||
},
|
||||
_ if status.is_server_error() => ProviderError::ServerError(format!("{:?}", payload)),
|
||||
_ if status.is_server_error() => {
|
||||
let msg = if let Some(p) = &payload {
|
||||
format!("HTTP {}: {:?}", status.as_u16(), p)
|
||||
} else {
|
||||
format!(
|
||||
"HTTP {}: No response body received from server",
|
||||
status.as_u16()
|
||||
)
|
||||
};
|
||||
ProviderError::ServerError(msg)
|
||||
}
|
||||
_ => ProviderError::RequestFailed(format!("Request failed with status: {}", status)),
|
||||
};
|
||||
|
||||
@@ -296,10 +306,20 @@ pub async fn handle_response_google_compat(response: Response) -> Result<Value,
|
||||
})
|
||||
}
|
||||
_ if final_status.is_server_error() => {
|
||||
Err(ProviderError::ServerError(format!("{:?}", payload)))
|
||||
let msg = if let Some(p) = &payload {
|
||||
format!("HTTP {}: {:?}", final_status.as_u16(), p)
|
||||
} else {
|
||||
format!("HTTP {}: No response body received from server", final_status.as_u16())
|
||||
};
|
||||
Err(ProviderError::ServerError(msg))
|
||||
}
|
||||
StatusCode::INTERNAL_SERVER_ERROR | StatusCode::SERVICE_UNAVAILABLE => {
|
||||
Err(ProviderError::ServerError(format!("{:?}", payload)))
|
||||
let msg = if let Some(p) = &payload {
|
||||
format!("HTTP {}: {:?}", final_status.as_u16(), p)
|
||||
} else {
|
||||
format!("HTTP {}: No response body received from server", final_status.as_u16())
|
||||
};
|
||||
Err(ProviderError::ServerError(msg))
|
||||
}
|
||||
_ => {
|
||||
tracing::debug!(
|
||||
@@ -1112,13 +1132,13 @@ mod tests {
|
||||
(
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
None,
|
||||
ProviderError::ServerError("None".to_string()),
|
||||
ProviderError::ServerError("HTTP 500: No response body received from server".to_string()),
|
||||
),
|
||||
// is_server_error() with payload
|
||||
(
|
||||
StatusCode::BAD_GATEWAY,
|
||||
Some(json!({"error": "upstream error"})),
|
||||
ProviderError::ServerError("Some(Object {\"error\": String(\"upstream error\")})".to_string()),
|
||||
ProviderError::ServerError("HTTP 502: Object {\"error\": String(\"upstream error\")}".to_string()),
|
||||
),
|
||||
// Default - any other status code
|
||||
(
|
||||
|
||||
Reference in New Issue
Block a user