misskey_http/
error.rs

1use std::convert::Infallible;
2
3use thiserror::Error;
4
5/// Possible errors from HTTP client.
6#[derive(Debug, Error)]
7pub enum Error {
8    /// Errors from underlying [isahc](https://docs.rs/isahc) library.
9    #[error("network error: {0}")]
10    Network(#[from] isahc::Error),
11    /// IO error.
12    #[error("IO error: {0}")]
13    Io(#[from] std::io::Error),
14    /// JSON encode/decode error.
15    #[error("JSON error: {0}")]
16    Json(#[from] serde_json::Error),
17    /// Invalid URL.
18    #[error("Invalid URL: {0}")]
19    InvalidUrl(#[from] url::ParseError),
20}
21
22impl From<Infallible> for Error {
23    fn from(x: Infallible) -> Error {
24        match x {}
25    }
26}
27
28/// Specialized Result type for operations on [`HttpClient`][`crate::HttpClient`].
29pub type Result<T> = std::result::Result<T, Error>;
30
31#[cfg(test)]
32mod tests {
33    use super::Error;
34
35    #[test]
36    fn test_send() {
37        fn assert_send<T: Send>() {}
38        assert_send::<Error>();
39    }
40
41    #[test]
42    fn test_sync() {
43        fn assert_send<T: Sync>() {}
44        assert_send::<Error>();
45    }
46}