use chrono;
use sodium_sys;
use std::error::Error;
use std::fmt;
use std::string::FromUtf8Error;
#[derive(Debug)]
pub enum AWSAuthError {
FromUtf8Error(FromUtf8Error),
ModeError,
Nacl(sodium_sys::SSError),
Other(&'static str),
ParseError(chrono::ParseError),
}
impl Error for AWSAuthError {
fn description(&self) -> &str {
match *self {
AWSAuthError::FromUtf8Error(ref e) => e.description(),
AWSAuthError::ModeError => "ModeError",
AWSAuthError::Nacl(_) => "Sodium SSError",
AWSAuthError::Other(e) => e,
AWSAuthError::ParseError(ref e) => e.description(),
}
}
}
impl fmt::Display for AWSAuthError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let display = match *self {
AWSAuthError::FromUtf8Error(_) => "FromUtf8Error",
AWSAuthError::ModeError => "ModeError",
AWSAuthError::Nacl(_) => "SSError",
AWSAuthError::Other(e) => e,
AWSAuthError::ParseError(_) => "ParseError",
};
write!(f, "{}", display)
}
}
impl From<sodium_sys::SSError> for AWSAuthError {
fn from(e: sodium_sys::SSError) -> AWSAuthError {
AWSAuthError::Nacl(e)
}
}
impl From<FromUtf8Error> for AWSAuthError {
fn from(e: FromUtf8Error) -> AWSAuthError {
AWSAuthError::FromUtf8Error(e)
}
}
impl From<chrono::format::ParseError> for AWSAuthError {
fn from(e: chrono::format::ParseError) -> AWSAuthError {
AWSAuthError::ParseError(e)
}
}
#[derive(Debug,PartialEq)]
pub struct ParseRegionError;
impl Error for ParseRegionError {
fn description(&self) -> &str {
"Unable to parse the given region"
}
}
impl fmt::Display for ParseRegionError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "ParseRegionError")
}
}
#[derive(Debug,PartialEq)]
pub struct ParseServiceError;
impl Error for ParseServiceError {
fn description(&self) -> &str {
"Unable to parse the given region"
}
}
impl fmt::Display for ParseServiceError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "ParseServiceError")
}
}