1pub use http::StatusCode;
4
5use std::error;
6use std::fmt::{self, Display, Formatter};
7use std::str::Utf8Error;
8
9#[derive(Debug)]
11pub enum Error<E = Box<dyn error::Error + Send + Sync>> {
12 Http(StatusCode),
14 Service(E),
16 Utf8(Utf8Error),
18}
19
20impl<E: error::Error + 'static> error::Error for Error<E> {
21 fn source(&self) -> Option<&(dyn error::Error + 'static)> {
22 use crate::Error::*;
23
24 match *self {
25 Http(_) => None,
26 Service(ref e) => Some(e),
27 Utf8(ref e) => Some(e),
28 }
29 }
30}
31
32impl<E: Display> Display for Error<E> {
33 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
34 use crate::Error::*;
35
36 match *self {
37 Http(ref code) => write!(f, "HTTP status code: {}", code),
38 Service(ref e) => write!(f, "HTTP client error: {}", e),
39 Utf8(ref e) => Display::fmt(e, f),
40 }
41 }
42}