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
pub mod http;
use std::{error, fmt};
pub trait RequestFactory {
fn build_request(&self) -> crate::objects::RequestBuilder;
}
#[derive(Debug)]
pub enum Error<E> {
BatchDuplicateResponseId(serde_json::Value),
Connection(E),
EmptyBatch,
Json(serde_json::Error),
NonceMismatch,
VersionMismatch,
WrongBatchResponseId(serde_json::Value),
WrongBatchResponseSize,
}
impl<E: fmt::Display> fmt::Display for Error<E> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let printable = match self {
Error::BatchDuplicateResponseId(err) => {
return write!(f, "duplicate batch response id, {}", err)
}
Error::Connection(err) => return err.fmt(f),
Error::EmptyBatch => "empty batch",
Error::Json(err) => return err.fmt(f),
Error::NonceMismatch => "nonce mismatch",
Error::VersionMismatch => "version mismatch",
Error::WrongBatchResponseId(err) => {
return write!(f, "wrong batch response id, {}", err)
}
Error::WrongBatchResponseSize => "wrong batch response size",
};
write!(f, "{}", printable)
}
}
impl<E: fmt::Display + fmt::Debug> error::Error for Error<E> {}