pub use http::StatusCode;
use std::error;
use std::fmt::{self, Display, Formatter};
use std::str::Utf8Error;
#[derive(Debug)]
pub enum Error<E = Box<dyn error::Error + Send + Sync>> {
Http(StatusCode),
Service(E),
Utf8(Utf8Error),
}
impl<E: error::Error + 'static> error::Error for Error<E> {
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
use crate::Error::*;
match *self {
Http(_) => None,
Service(ref e) => Some(e),
Utf8(ref e) => Some(e),
}
}
}
impl<E: Display> Display for Error<E> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
use crate::Error::*;
match *self {
Http(ref code) => write!(f, "HTTP status code: {}", code),
Service(ref e) => write!(f, "HTTP client error: {}", e),
Utf8(ref e) => Display::fmt(e, f),
}
}
}