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
use self::ZomeApiError::*;
use serde_json;
use std::{error::Error, fmt};
pub type ZomeApiResult<T> = Result<T, ZomeApiError>;
#[derive(Debug, Serialize)]
pub enum ZomeApiError {
Internal(String),
FunctionNotImplemented,
HashNotFound,
ValidationFailed(String),
}
impl ZomeApiError {
pub fn to_json(&self) -> serde_json::Value {
json!({ "error": self })
}
}
impl Error for ZomeApiError {
#[cfg_attr(rustfmt, rustfmt_skip)]
fn description(&self) -> &str {
match self {
Internal(msg) => &msg,
FunctionNotImplemented => "Function not implemented",
HashNotFound => "Hash not found",
ValidationFailed(msg) => &msg,
}
}
}
impl fmt::Display for ZomeApiError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:?}", self)
}
}