From 96a2ebf37a59cbdfcb5577a9a2e6b7b6a0bce3e6 Mon Sep 17 00:00:00 2001 From: Adil Hafeez Date: Fri, 6 Mar 2026 14:10:35 +0000 Subject: [PATCH] fix: add missing ResponseHandler methods and use BrightStaffError --- .../src/handlers/agents/orchestrator.rs | 2 +- crates/brightstaff/src/handlers/response.rs | 35 ++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/crates/brightstaff/src/handlers/agents/orchestrator.rs b/crates/brightstaff/src/handlers/agents/orchestrator.rs index e6ec26fc..5af69af1 100644 --- a/crates/brightstaff/src/handlers/agents/orchestrator.rs +++ b/crates/brightstaff/src/handlers/agents/orchestrator.rs @@ -29,7 +29,7 @@ pub enum AgentFilterChainError { #[error("Pipeline processing error: {0}")] Pipeline(#[from] PipelineError), #[error("Response handling error: {0}")] - Response(#[from] crate::handlers::response::ResponseError), + Response(#[from] common::errors::BrightStaffError), #[error("Request parsing error: {0}")] RequestParsing(#[from] serde_json::Error), #[error("HTTP error: {0}")] diff --git a/crates/brightstaff/src/handlers/response.rs b/crates/brightstaff/src/handlers/response.rs index e9862d2f..7861ba16 100644 --- a/crates/brightstaff/src/handlers/response.rs +++ b/crates/brightstaff/src/handlers/response.rs @@ -27,6 +27,39 @@ impl ResponseHandler { .boxed() } + /// Create a JSON error response with BAD_REQUEST status + pub fn create_json_error_response( + json: &serde_json::Value, + ) -> Response> { + let body = Self::create_full_body(json.to_string()); + let mut response = Response::new(body); + *response.status_mut() = hyper::StatusCode::BAD_REQUEST; + response.headers_mut().insert( + hyper::header::CONTENT_TYPE, + "application/json".parse().unwrap(), + ); + response + } + + /// Create a BAD_REQUEST error response with a message + pub fn create_bad_request(message: &str) -> Response> { + let json = serde_json::json!({"error": message}); + Self::create_json_error_response(&json) + } + + /// Create an INTERNAL_SERVER_ERROR response with a message + pub fn create_internal_error(message: &str) -> Response> { + let json = serde_json::json!({"error": message}); + let body = Self::create_full_body(json.to_string()); + let mut response = Response::new(body); + *response.status_mut() = hyper::StatusCode::INTERNAL_SERVER_ERROR; + response.headers_mut().insert( + hyper::header::CONTENT_TYPE, + "application/json".parse().unwrap(), + ); + response + } + /// Create a streaming response from a reqwest response. /// The spawned streaming task is instrumented with both `agent_span` and `orchestrator_span` /// so their durations reflect the actual time spent streaming to the client. @@ -113,7 +146,7 @@ impl ResponseHandler { SupportedUpstreamAPIs::OpenAIChatCompletions(OpenAIApi::ChatCompletions); let sse_iter = SseStreamIter::try_from(response_bytes.as_ref()).map_err(|e| { - ResponseError::StreamError(format!("Failed to parse SSE stream: {}", e)) + BrightStaffError::StreamError(format!("Failed to parse SSE stream: {}", e)) })?; let mut accumulated_text = String::new();