#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("invalid profile: {0}")]
InvalidProfile(String),
#[error("fetch retry error: {0}")]
FetchRetry(objectiveai_sdk::error::ResponseError),
#[error("retry not found")]
RetryNotFound,
#[error("fetch cache vote error: {0}")]
FetchCacheVote(objectiveai_sdk::error::ResponseError),
#[error("fetch swarm error: {0}")]
FetchSwarm(objectiveai_sdk::error::ResponseError),
#[error("swarm not found")]
SwarmNotFound,
#[error("invalid swarm: {0}")]
InvalidSwarm(String),
#[error("expected two or more request vector responses, got {0}")]
ExpectedTwoOrMoreRequestVectorResponses(usize),
#[error("from_cache and continuation are mutually exclusive")]
CacheAndContinuationConflict,
}
impl objectiveai_sdk::error::StatusError for Error {
fn status(&self) -> u16 {
match self {
Error::InvalidProfile(_) => 400,
Error::FetchRetry(e) => e.status(),
Error::RetryNotFound => 404,
Error::FetchCacheVote(e) => e.status(),
Error::FetchSwarm(e) => e.status(),
Error::SwarmNotFound => 404,
Error::InvalidSwarm(_) => 400,
Error::ExpectedTwoOrMoreRequestVectorResponses(_) => 400,
Error::CacheAndContinuationConflict => 400,
}
}
fn message(&self) -> Option<serde_json::Value> {
Some(serde_json::json!({
"kind": "vector",
"error": match self {
Error::InvalidProfile(msg) => serde_json::json!({
"kind": "invalid_profile",
"error": msg,
}),
Error::FetchRetry(e) => serde_json::json!({
"kind": "fetch_retry",
"error": e.message(),
}),
Error::RetryNotFound => serde_json::json!({
"kind": "retry_not_found",
"error": "retry not found",
}),
Error::FetchCacheVote(e) => serde_json::json!({
"kind": "fetch_cache_vote",
"error": e.message(),
}),
Error::FetchSwarm(e) => serde_json::json!({
"kind": "fetch_swarm",
"error": e.message(),
}),
Error::SwarmNotFound => serde_json::json!({
"kind": "swarm_not_found",
"error": "swarm not found",
}),
Error::InvalidSwarm(msg) => serde_json::json!({
"kind": "invalid_swarm",
"error": msg,
}),
Error::ExpectedTwoOrMoreRequestVectorResponses(n) => serde_json::json!({
"kind": "expected_two_or_more_request_vector_responses",
"error": format!("expected two or more request vector responses, got {}", n),
}),
Error::CacheAndContinuationConflict => serde_json::json!({
"kind": "cache_and_continuation_conflict",
"error": "from_cache and continuation are mutually exclusive",
}),
}
}))
}
}