download_async/
error.rs

1use std::{error::Error as StdError, fmt::Display};
2
3#[derive(Debug)]
4pub enum Error {
5    Decode(std::io::Error),
6    TimedOut(),
7    InvalidBody(BoxError),
8    NoneValue(String),
9    InvalidHeaderValue(http::header::InvalidHeaderValue),
10    StatusError(http::StatusCode),
11    IoError(std::io::Error),
12    HyperError(BoxError),
13    HttpError(BoxError),
14}
15
16
17impl Display for Error {
18    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
19        f.write_str("")
20    }
21}
22
23impl StdError for Error { }
24
25
26pub(crate) type BoxError = Box<dyn StdError + Send + Sync>;
27
28#[allow(unused)]
29pub(crate) fn decode_io(e: std::io::Error) -> Error {
30    if e.get_ref().map(|r| r.is::<Error>()).unwrap_or(false) {
31        *e.into_inner()
32            .expect("io::Error::get_ref was Some(_)")
33            .downcast::<Error>()
34            .expect("StdError::is() was true")
35    } else {
36        Error::Decode(e)
37    }
38}
39
40impl From<http::header::InvalidHeaderValue> for Error {
41    #[inline(always)]
42    fn from(error: http::header::InvalidHeaderValue) -> Self {
43        Self::InvalidHeaderValue(error)
44    }
45}
46
47impl From<std::io::Error> for Error {
48    #[inline(always)]
49    fn from(error: std::io::Error) -> Self {
50      Self::IoError(error)
51    }
52}
53
54impl From<hyper::Error> for Error {
55    #[inline(always)]
56    fn from(error: hyper::Error) -> Self {
57      Self::HyperError(error.into())
58    }
59}
60
61impl From<http::Error> for Error {
62    #[inline(always)]
63    fn from(error: http::Error) -> Self {
64      Self::HttpError(error.into())
65    }
66}