use crate::errors::AppError;
use crate::retry::AttemptOutcome;
#[derive(Debug)]
pub struct ChatError {
pub source: AppError,
pub finish_reason: Option<String>,
pub prompt_tokens: Option<u32>,
pub completion_tokens: Option<u32>,
pub retry_class: AttemptOutcome,
}
impl ChatError {
pub(super) fn new(source: AppError, retry_class: AttemptOutcome) -> Self {
Self {
source,
finish_reason: None,
prompt_tokens: None,
completion_tokens: None,
retry_class,
}
}
pub(super) fn with_diagnostics(
source: AppError,
finish_reason: Option<String>,
prompt_tokens: Option<u32>,
completion_tokens: Option<u32>,
retry_class: AttemptOutcome,
) -> Self {
Self {
source,
finish_reason,
prompt_tokens,
completion_tokens,
retry_class,
}
}
}
impl std::fmt::Display for ChatError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(&self.source, f)
}
}
impl std::error::Error for ChatError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
Some(&self.source)
}
}
pub(super) fn reasoning_disable_rejected(err: &ChatError) -> bool {
let msg = err.source.to_string().to_lowercase();
msg.contains("400") && msg.contains("reasoning")
}