diff --git a/router/src/server.rs b/router/src/server.rs index 76e1fce1..da63e9b1 100644 --- a/router/src/server.rs +++ b/router/src/server.rs @@ -849,10 +849,10 @@ async fn completions( yield Ok(event); } Err(err) => { - let error_event: ErrorEvent = err.into(); - let event = Event::default().json_data(error_event).unwrap_or_else(|e| { - InferError::StreamSerializationError(e.to_string()).into() - }); + let event = Event::default() + .json_data(ErrorEvent::into_api_error(err, 422)) + .unwrap_or_else(|e| InferError::StreamSerializationError(e.to_string()).into()); + println!("{:?}", event); yield Ok::(event); break } @@ -1358,10 +1358,9 @@ async fn chat_completions( } } Err(err) => { - let error_event: ErrorEvent = err.into(); - let event = Event::default().json_data(error_event).unwrap_or_else(|e| { - InferError::StreamSerializationError(e.to_string()).into() - }); + let event = Event::default() + .json_data(ErrorEvent::into_api_error(err, 422)) + .unwrap_or_else(|e| InferError::StreamSerializationError(e.to_string()).into()); yield Ok::(event); break; } @@ -2525,7 +2524,7 @@ impl From for Event { #[derive(serde::Serialize)] pub struct APIError { message: String, - http_status_code: i32, + http_status_code: usize, } #[derive(serde::Serialize)] @@ -2533,12 +2532,12 @@ pub struct ErrorEvent { error: APIError, } -impl From for ErrorEvent { - fn from(err: InferError) -> Self { +impl ErrorEvent { + fn into_api_error(err: InferError, http_status_code: usize) -> Self { ErrorEvent { error: APIError { message: err.to_string(), - http_status_code: 500, + http_status_code, }, } }