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