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
use std::result;
use std::convert::From;
use shuttle_core;
use reqwest;

/// Error type.
#[derive(Debug)]
pub enum Error {
    /// Error that can occur when connecting non secure horizon server.
    UnsecureConnection,
    /// Error that can occur when interacting with HTTP.
    HttpError(reqwest::Error),
    /// Error that can occur when parsing HTTP URL.
    HttpParseError(reqwest::UrlError),
    /// Error that originates from `shuttle_core`.
    Core(shuttle_core::Error),
    /// Errror that can occur when deserializing json.
    DeserializeError,
    /// Generic error
    Error,
}

/// A `Result` alias where `Error` is a `shuttle_sdk::Error`.
pub type Result<T> = result::Result<T, Error>;

impl From<reqwest::Error> for Error {
    fn from(err: reqwest::Error) -> Error {
        Error::HttpError(err)
    }
}

impl From<reqwest::UrlError> for Error {
    fn from(err: reqwest::UrlError) -> Error {
        Error::HttpParseError(err)
    }
}

impl From<shuttle_core::Error> for Error {
    fn from(err: shuttle_core::Error) -> Error {
        Error::Core(err)
    }
}

impl From<()> for Error {
    fn from(_err: ()) -> Error {
        Error::Error
    }
}