use std::fmt;
use std::fmt::{Debug, Display, Formatter};
#[cfg(feature = "network")]
pub struct HttpError {
status_code: u16,
}
#[cfg(feature = "network")]
impl HttpError {
pub fn new(status_code: u16) -> HttpError {
HttpError { status_code }
}
pub fn status_code(&self) -> u16 {
self.status_code
}
}
#[cfg(feature = "network")]
impl Debug for HttpError {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "Http error: {}", self.status_code)
}
}
#[cfg(feature = "network")]
impl Display for HttpError {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "Http error: {}", self.status_code)
}
}
#[cfg(feature = "network")]
impl std::error::Error for HttpError {}
pub struct FeatureDisabledError {
name: String,
}
impl FeatureDisabledError {
pub fn new(name: String) -> Self {
FeatureDisabledError { name }
}
pub fn name(&self) -> &str {
self.name.as_str()
}
}
impl Debug for FeatureDisabledError {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "FeatureDisabledError: '{}' is not compiled into this binary", self.name)
}
}
impl Display for FeatureDisabledError {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "The feature '{}' is currently disabled. Please recompile with the appropriate feature flag.", self.name)
}
}
impl std::error::Error for FeatureDisabledError {}