pub use hyper::Error as HyperError;
pub use hyper::error::ParseError as UrlError;
pub type MultipartError = ::multipart::client::lazy::LazyIoError<'static>;
use net::request::RequestHead;
use serialize::none::NoSerializeError;
use std::io::Error as IoError;
use std::error::Error as StdError;
use std::fmt;
quick_error! {
#[derive(Debug)]
pub enum Error {
Hyper(e: HyperError) {
from()
cause(e)
description(e.description())
}
Url(e: UrlError) {
from()
cause(e)
description(e.description())
}
Serialize(e: Box<StdError + Send + 'static>) {
cause(&**e)
description(e.description())
}
Deserialize(e: Box<StdError + Send + 'static>) {
cause(&**e)
description(e.description())
}
StdIo(e: IoError){
from()
cause(e)
description(e.description())
}
Multipart(e: MultipartError) {
from()
cause(e)
description(e.description())
}
NoSerialize(e: NoSerializeError) {
from()
cause(e)
description(e.description())
}
Other(e: Box<StdError + Send + 'static>){
from()
cause(&**e)
description(e.description())
}
Panic(e: RequestPanicked) {
from()
cause(e)
description(e.description())
}
UnknownPanic {
from(::futures::Canceled)
description("A panic occurred during a callback assigned to a request.")
}
ResultTaken {
description("The result has already been taken from this Call.")
}
}
}
impl Error {
pub fn map_serialize<T, E: StdError + Send + 'static>(res: Result<T, E>) -> Result<T, Self> {
res.map_err(|e| Error::Serialize(Box::new(e)))
}
pub fn map_deserialize<T, E: StdError + Send + 'static>(res: Result<T, E>) -> Result<T, Self> {
res.map_err(|e| Error::Deserialize(Box::new(e)))
}
pub fn deserialize<E: Into<Box<StdError + Send + Sync + 'static>>>(err: E) -> Self {
Error::Deserialize(err.into())
}
}
pub fn flatten_res<T, E>(res: Result<Result<T, Error>, E>) -> Result<T, Error> where Error: From<E> {
try!(res)
}
#[derive(Debug)]
pub struct RequestPanicked(pub RequestHead);
impl fmt::Display for RequestPanicked {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Panic while executing request: \"{}\"", self.0)
}
}
impl StdError for RequestPanicked {
fn description(&self) -> &str {
"A panic occurred while executing a request."
}
}