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
//! Error types returned by the `GraphClient`

use std::error::Error;
use std::fmt;
use std::string::FromUtf8Error;
use std::io;
use hyper;
use url;
use serde_json;
use time;
use semver::SemVerError;

#[cfg(feature = "rustc-serialize")]
use rustc_serialize::json as rustc_json;

#[derive(Clone, Debug, Deserialize)]
pub struct Neo4jError {
    pub message: String,
    pub code: String,
}

#[derive(Debug)]
pub struct TimeParseError(time::ParseError, String);

impl fmt::Display for TimeParseError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "{}", self.0)
    }
}

impl Error for TimeParseError {
    fn description(&self) -> &str {
        &self.1
    }
}

quick_error! {
    #[derive(Debug)]
    pub enum GraphError {
        Neo4j(err: Vec<Neo4jError>) {
            from()
        }
        Statement(err: String) {}
        Transaction(err: String) {}
        Io(err: io::Error) {
            from()
        }
        FromUtf8(err: FromUtf8Error) {
            from()
        }
        UrlParse(err: url::ParseError) {
            from()
        }
        Hyper(err: hyper::Error) {
            from()
        }
        Serde(err: serde_json::Error) {
            from()
        }
        TimeParse(err: time::ParseError) {
            from()
        }
        SemVer(err: SemVerError) {
            from()
        }
        Other(err: String) {
            from()
        }
    }
}

#[cfg(feature = "rustc-serialize")]
impl From<rustc_json::DecoderError> for GraphError {
    fn from(e: rustc_json::DecoderError) -> GraphError {
        GraphError::Other(format!("DecoderError: {}", e))
    }
}