devin15/cursor2api-rust
0
1use super::ErrorResponse;2 3pub enum ChatError {4 ModelNotSupported(String),5 EmptyMessages,6 NoTokens,7 RequestFailed(String),8 Unauthorized,9}10 11impl ChatError {12 pub fn to_json(&self) -> ErrorResponse {13 let (error, message) = match self {14 ChatError::ModelNotSupported(model) => (15 "model_not_supported",16 format!("Model '{}' is not supported", model),17 ),18 ChatError::EmptyMessages => (19 "empty_messages",20 "Message array cannot be empty".to_string(),21 ),22 ChatError::NoTokens => ("no_tokens", "No available tokens".to_string()),23 ChatError::RequestFailed(err) => ("request_failed", format!("Request failed: {}", err)),24 ChatError::Unauthorized => ("unauthorized", "Invalid authorization token".to_string()),25 };26 27 ErrorResponse {28 status: super::ApiStatus::Error,29 code: None,30 error: Some(error.to_string()),31 message: Some(message),32 }33 }34}35 