1#![allow(dead_code)]
2use std::fmt::{Result,Display,Formatter,Debug};
3use reqwest;
4use std::env::var;
5use serde::Deserialize as des;
6use rmp_serde::decode;
7pub type ConnectionError=reqwest::Error;
8
9pub type DError=decode::Error;
10
11#[derive(des,Debug)]
12pub struct MsfError {
13 pub error:bool,
14 pub error_class:String,
15 pub error_string:String,
16 pub error_message:String,
17 pub error_backtrace:Vec<String>,
18}
19
20impl std::error::Error for MsfError {}
21
22impl Display for MsfError {
23 fn fmt(&self,f: &mut Formatter) -> Result {
24 let err:String;
25 match var("RUST_BACKTRACE") {
26 Ok(val) => {
27 if val=="1".to_string() {
28 err=format!("({},{})",self.error_message,self.error_class).to_string()
29 } else if val=="full".to_string() {
30 err=format!("{:?}",self).to_string();
31 } else {
32 err=format!("{}",self.error_message).to_string();
33 }
34 },
35 Err(_) => {
36 err=format!("{}",self.error_message);
37 },
38 }
39 write!(f,"{}",err)
40 }
41}
42
43#[derive(Debug)]
44pub enum Error {
45 ConnectionError(ConnectionError),
46 DError(DError),
47 MsfError(MsfError),
48}
49
50impl std::error::Error for Error {}
51impl Display for Error {
52 fn fmt(&self,f:&mut Formatter) -> Result {
53 match self {
54 Error::ConnectionError(e) => Display::fmt(&e,f),
55 Error::DError(e) => Display::fmt(&e,f),
56 Error::MsfError(e) => Display::fmt(&e,f),
57 }
58 }
59}
60
61impl From<ConnectionError> for Error {
62 fn from(e:ConnectionError) -> Error {
63 Error::ConnectionError(e)
64 }
65}
66impl From<DError> for Error {
67 fn from(e:DError) -> Error {
68 Error::DError(e)
69 }
70}
71impl From<MsfError> for Error {
72 fn from(e:MsfError) -> Error {
73 Error::MsfError(e)
74 }
75}