use thiserror::Error;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Error, Debug)]
pub enum Error {
#[error("Service not found: {0}")]
ServiceNotFound(String),
#[error("Service registration failed: {0}")]
RegistrationError(String),
#[error("Async service initialization failed: {0}")]
ContainerError(String),
#[error("HTTP server error: {0}")]
ServerError(String),
#[error("Route registration failed: {0}")]
RouteError(String),
#[error("Error: {0}")]
Other(String),
}
impl Error {
pub fn service_not_found(service_name: impl Into<String>) -> Self {
Self::ServiceNotFound(service_name.into())
}
pub fn registration_error(msg: impl Into<String>) -> Self {
Self::RegistrationError(msg.into())
}
pub fn container_error(msg: impl Into<String>) -> Self {
Self::ContainerError(msg.into())
}
pub fn server_error(msg: impl Into<String>) -> Self {
Self::ServerError(msg.into())
}
pub fn route_error(msg: impl Into<String>) -> Self {
Self::RouteError(msg.into())
}
pub fn other(msg: impl Into<String>) -> Self {
Self::Other(msg.into())
}
}