From c82cfaa8a3763db9c79cb86ba36e393a08903ce5 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Sat, 21 Jun 2025 09:56:00 -0400 Subject: [PATCH] report hostname on error --- .../storyteller_client/src/error/api_error.rs | 8 ++++++-- .../src/utils/filter_bad_response.rs | 12 +++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/crates/lib/api_clients/storyteller_client/src/error/api_error.rs b/crates/lib/api_clients/storyteller_client/src/error/api_error.rs index a39cdc4e47..d0bf2c6b61 100644 --- a/crates/lib/api_clients/storyteller_client/src/error/api_error.rs +++ b/crates/lib/api_clients/storyteller_client/src/error/api_error.rs @@ -21,7 +21,10 @@ pub enum ApiError { TooManyRequests(String), /// 500. An internal server error occurred. - InternalServerError(String), + InternalServerError { + body: String, + backend_hostname: Option, + }, /// A deserialization error with the response. DeserializationError(serde_json::Error), @@ -53,7 +56,8 @@ impl Display for ApiError { ApiError::Forbidden(msg) => write!(f, "Forbidden: {}", msg), ApiError::NotFound(msg) => write!(f, "Not found: {}", msg), ApiError::TooManyRequests(msg) => write!(f, "Too many requests: {}", msg), - ApiError::InternalServerError(msg) => write!(f, "Internal server error: {}", msg), + ApiError::InternalServerError {body, backend_hostname} => + write!(f, "Internal Server Error; backend hostname: {:?} ; body: {}; ", backend_hostname, body), // Server response handling errors ApiError::DeserializationError(error) => write!(f, "Deserialization error: {}", error), // Network errors diff --git a/crates/lib/api_clients/storyteller_client/src/utils/filter_bad_response.rs b/crates/lib/api_clients/storyteller_client/src/utils/filter_bad_response.rs index aecf663d3c..c446a31582 100644 --- a/crates/lib/api_clients/storyteller_client/src/utils/filter_bad_response.rs +++ b/crates/lib/api_clients/storyteller_client/src/utils/filter_bad_response.rs @@ -1,6 +1,7 @@ use crate::error::api_error::ApiError; use crate::utils::status_codes::*; use anyhow::anyhow; +use log::error; /// Pass request errors to this method for standard error handling behavior. /// This function needs to take temporary ownership, but will return it to the caller. @@ -13,6 +14,15 @@ pub async fn filter_bad_response(response: reqwest::Response) -> Result text.to_string(), Err(err) => format!("Could not read response body: {:?}", err), @@ -23,7 +33,7 @@ pub async fn filter_bad_response(response: reqwest::Response) -> Result Err(ApiError::Forbidden(response_body)), STATUS_404_NOT_FOUND => Err(ApiError::NotFound(response_body)), STATUS_429_TOO_MANY_REQUESTS => Err(ApiError::TooManyRequests(response_body)), - STATUS_500_INTERNAL_SERVER_ERROR => Err(ApiError::InternalServerError(response_body)), + STATUS_500_INTERNAL_SERVER_ERROR => Err(ApiError::InternalServerError { body: response_body, backend_hostname }), _ => Err(ApiError::Other(anyhow!("Bad status code: {}; message: {:?}", status, response_body))), } }