uiuifree_elastic/
error.rs1use std::fmt::Display;
2use std::fmt::Formatter;
3#[derive(Debug)]
4pub enum ElasticError {
5 Connection(String),
6 Send(String),
7 JsonParse(String),
8 Status(u16, String),
9 Response(String),
10 NotFound(String),
11}
12
13impl ElasticError {
14 #[allow(dead_code)]
15 fn error(&self) -> Option<String> {
16 let value = self.to_owned();
17 match value {
18 ElasticError::JsonParse(e) => Some(e.to_string()),
19 ElasticError::Response(e) => Some(e.to_string()),
20 ElasticError::Connection(e) => Some(e.to_string()),
21 ElasticError::Status(_, e) => Some(e.to_string()),
22 ElasticError::Send(e) => Some(e.to_string()),
23 ElasticError::NotFound(e) => Some(e.to_string()),
24 }
25 }
26}
27
28impl Display for ElasticError {
29 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
30 let error = self.error();
31 write!(f, "{}", error.unwrap_or_default())
32 }
33}