use std::fmt;
#[derive(Debug)]
pub enum Error {
NotInPod(String),
NotWired(String),
Denied { path: String, body: String },
Api {
status: u16,
path: String,
body: String,
},
Transport { path: String, source: String },
Decode { path: String, source: String },
Invalid(String),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::NotInPod(m) => write!(f, "ctxmesh: not running in a ctxmesh pod ({m})"),
Error::NotWired(m) => write!(f, "ctxmesh: capability not wired for this agent: {m}"),
Error::Denied { path, body } => {
write!(f, "ctxmesh: {path} denied by the platform: {body}")
}
Error::Api { status, path, body } => {
write!(f, "ctxmesh: {path} returned {status}: {body}")
}
Error::Transport { path, source } => write!(f, "ctxmesh: {path}: {source}"),
Error::Decode { path, source } => {
write!(f, "ctxmesh: decode response from {path}: {source}")
}
Error::Invalid(m) => write!(f, "ctxmesh: {m}"),
}
}
}
impl std::error::Error for Error {}