use objectiveai_sdk::error::StatusError;
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("invention error: {0}")]
Invention(#[from] crate::functions::inventions::Error),
#[error("invention failed: {0}")]
InventionFirstChunk(objectiveai_sdk::error::ResponseError),
}
impl StatusError for Error {
fn status(&self) -> u16 {
match self {
Error::Invention(e) => e.status(),
Error::InventionFirstChunk(e) => e.code,
}
}
fn message(&self) -> Option<serde_json::Value> {
let error_value = match self {
Error::Invention(e) => serde_json::json!({
"kind": "invention",
"error": e.message(),
}),
Error::InventionFirstChunk(e) => serde_json::json!({
"kind": "invention_first_chunk",
"error": e.message,
}),
};
Some(serde_json::json!({
"kind": "recursive_invention",
"error": error_value,
}))
}
}