use self::Kind::*;
use http::status::StatusCode;
#[derive(Debug)]
pub struct Error {
kind: Kind,
}
#[derive(Debug)]
enum Kind {
Missing,
Invalid(String),
Web(::Error),
}
impl Error {
pub fn missing_argument() -> Error {
Error { kind: Missing }
}
pub fn is_missing_argument(&self) -> bool {
match self.kind {
Missing => true,
_ => false,
}
}
pub fn invalid_argument<T: ToString>(reason: &T) -> Error {
Error { kind: Invalid(reason.to_string()) }
}
pub fn is_invalid_argument(&self) -> bool {
match self.kind {
Invalid(_) => true,
_ => false,
}
}
pub(crate) fn internal_error() -> Error {
::Error::from(StatusCode::BAD_REQUEST).into()
}
}
impl From<Error> for ::Error {
fn from(err: Error) -> Self {
match err.kind {
Missing | Invalid(_) => ::Error::from(StatusCode::BAD_REQUEST),
Web(err) => err,
}
}
}
impl From<::Error> for Error {
fn from(err: ::Error) -> Self {
Error { kind: Web(err) }
}
}