1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use core::fmt::{self, Display, Formatter};
#[cfg(feature = "std")]
use std::error::Error;
use crate::url;
#[derive(Debug, Clone)]
pub enum HttpURLError {
ParseError(url::ParseError),
ProtocolError,
LocalMust,
LocalNotAllow,
}
impl From<url::ParseError> for HttpURLError {
#[inline]
fn from(error: url::ParseError) -> Self {
HttpURLError::ParseError(error)
}
}
impl Display for HttpURLError {
#[inline]
fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
match self {
HttpURLError::ParseError(error) => Display::fmt(error, f),
HttpURLError::ProtocolError => {
f.write_str("need to use `http` or `https` as a protocol")
}
HttpURLError::LocalMust => f.write_str("must be local"),
HttpURLError::LocalNotAllow => f.write_str("must not be local"),
}
}
}
#[cfg(feature = "std")]
impl Error for HttpURLError {}