use compliance_core::CoreError; use thiserror::Error; #[derive(Error, Debug)] pub enum AgentError { #[error(transparent)] Core(#[from] CoreError), #[error("Database error: {0}")] Database(#[from] mongodb::error::Error), #[error("Git error: {0}")] Git(#[from] git2::Error), #[error("HTTP error: {0}")] Http(#[from] reqwest::Error), #[error("JSON error: {0}")] Json(#[from] serde_json::Error), #[error("IO error: {0}")] Io(#[from] std::io::Error), #[error("Scheduler error: {0}")] Scheduler(String), #[error("Configuration error: {0}")] Config(String), #[error(transparent)] Secret(#[from] crate::secrets::SecretError), #[error("Dynamic-execution error: {0}")] Exec(#[from] werkbank_exec::ExecError), /// An uploaded archive is password-protected and no password is set. #[error("the archive is password-protected; set its password on the target")] ArchivePasswordRequired, /// The password set for an uploaded archive does not open it. #[error("the archive password set on the target does not open it")] ArchivePasswordWrong, #[error("{0}")] Other(String), } impl From for axum::http::StatusCode { fn from(err: AgentError) -> Self { match err { AgentError::Core(CoreError::NotFound(_)) => axum::http::StatusCode::NOT_FOUND, _ => axum::http::StatusCode::INTERNAL_SERVER_ERROR, } } }