extern crate hyper;
use std::error::Error;
use std::fmt::{self, Debug};
use std::io;
use self::hyper::Error as TransportError;
use self::hyper::error::ParseError as HyperParseError;
#[derive(Debug, Clone, PartialEq, Deserialize)]
pub struct CrateDBError {
pub message: String,
pub code: String,
pub description: String,
}
impl CrateDBError {
pub fn new<S1, S2>(message: S1, code: S2) -> CrateDBError
where S1: Into<String>,
S2: Into<String>
{
let c = code.into();
let m = message.into();
let desc = format!("Error [Code {}]: {}", c, m);
CrateDBError {
message: m,
code: c,
description: desc,
}
}
}
impl fmt::Display for CrateDBError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Debug::fmt(self, f)
}
}
impl Error for CrateDBError {
fn description(&self) -> &str {
&self.description
}
}
#[derive(Debug)]
pub struct CrateDBConfigurationError {
pub description: String,
}
impl Error for CrateDBConfigurationError {
fn description(&self) -> &str {
&self.description
}
}
impl fmt::Display for CrateDBConfigurationError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Debug::fmt(&self.description, f)
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct BackendError {
pub description: String,
}
impl BackendError {
pub fn from_transport(error: TransportError) -> BackendError {
BackendError { description: format!("Error on Transport: {:?}", error) }
}
pub fn from_parser(error: HyperParseError) -> BackendError {
BackendError { description: format!("Error on Parse: {:?}", error) }
}
pub fn from_io(error: io::Error) -> BackendError {
BackendError { description: format!("Error on I/O: {:?}", error) }
}
pub fn new(error: String) -> BackendError {
BackendError { description: error }
}
}
impl Error for BackendError {
fn description(&self) -> &str {
&self.description
}
}
impl fmt::Display for BackendError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Debug::fmt(&self.description, f)
}
}
#[derive(Debug, Clone)]
pub enum BlobError {
Action(CrateDBError),
Transport(BackendError),
}