Skip to main content

provable_sdk/
error.rs

1use std::error::Error;
2use std::fmt::{Display, Formatter};
3
4#[derive(Debug, Clone, PartialEq, Eq)]
5pub struct ProvableError(pub String);
6
7impl ProvableError {
8    pub fn new(message: impl Into<String>) -> Self {
9        Self(message.into())
10    }
11}
12
13impl Display for ProvableError {
14    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
15        f.write_str(&self.0)
16    }
17}
18
19impl Error for ProvableError {}
20
21impl From<reqwest::Error> for ProvableError {
22    fn from(value: reqwest::Error) -> Self {
23        Self(value.to_string())
24    }
25}
26
27impl From<serde_json::Error> for ProvableError {
28    fn from(value: serde_json::Error) -> Self {
29        Self(value.to_string())
30    }
31}
32
33impl From<std::io::Error> for ProvableError {
34    fn from(value: std::io::Error) -> Self {
35        Self(value.to_string())
36    }
37}
38
39pub type Result<T> = std::result::Result<T, ProvableError>;