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

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

#[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: hyper::error::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()
        }
    }
}