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
//! Error handling for networking, json parsing and the API.
//! 
//! Networking errors are handled by [hyper](https://docs.rs/hyper/0.12.25/hyper/)
//!
//! Problems parsing JSON by [serde_json](https://docs.serde.rs/serde_json/error/index.html)
use super::*;
/// Errors relating to network requests or json serialiazation
#[derive(Debug)]
pub enum FetchError {
    Http(hyper::Error),
    Json(serde_json::Error),
}

impl From<hyper::Error> for FetchError {
    fn from(err: hyper::Error) -> FetchError {
        FetchError::Http(err)
    }
}

impl From<serde_json::Error> for FetchError {
    fn from(err: serde_json::Error) -> FetchError {
        FetchError::Json(err)
    }
}

struct ApiError {
    code: i16,
    message: &'static str
}

/// [Potential API errors](https://docs.factom.com/api?json#errors) returned by the server are enumerated by FactomError 
#[derive(Debug, Deserialize, PartialEq)]
pub enum FactomError {
    ParseError,
    InvalidRequest,
    InvalidParams,
    InternalError,
    MethodNotFound,
    RepeatedCommit,
    UndefinedError
}