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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#[cfg(feature = "client")]
use http;
#[cfg(feature = "client")]
use hyper;
use serde_xml_rs;
use std::fmt;
use std::string;
#[cfg(feature = "client")]
#[derive(Debug)]
pub enum RequestError {
InvalidDay,
URLParsingError(http::uri::InvalidUri),
BodyParsingError(string::FromUtf8Error),
XMLParsingError(ParsingError),
Http(http::Error),
Hyper(hyper::Error),
}
#[derive(Debug)]
pub enum ParsingError {
DocumentParsingError(serde_xml_rs::Error),
DateParsingError(String),
}
#[cfg(feature = "client")]
impl fmt::Display for RequestError {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
match self {
RequestError::InvalidDay => write!(formatter, "passed invalid day"),
RequestError::URLParsingError(ref error) => {
write!(formatter, "error parsing URL: {}", error)
}
RequestError::BodyParsingError(ref error) => {
write!(formatter, "error parsing HTTP response body: {}", error)
}
RequestError::XMLParsingError(ref error) => write!(formatter, "{}", error),
RequestError::Http(ref error) => write!(formatter, "{}", error),
RequestError::Hyper(ref error) => write!(formatter, "{}", error),
}
}
}
impl fmt::Display for ParsingError {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
match self {
ParsingError::DocumentParsingError(error) => {
write!(formatter, "error parsing XML document: {}", error)
}
ParsingError::DateParsingError(error) => {
write!(formatter, "error parsing vplan date: {}", error)
}
}
}
}
#[cfg(feature = "client")]
impl From<hyper::Error> for RequestError {
fn from(error: hyper::Error) -> Self {
RequestError::Hyper(error)
}
}
#[cfg(feature = "client")]
impl From<http::Error> for RequestError {
fn from(error: http::Error) -> Self {
RequestError::Http(error)
}
}