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
//! Noosphere errors

use crate::authority::Authorization;
use thiserror::Error;

/// High-level error types relevant to the Noosphere protocol
#[derive(Error, Debug)]
pub enum NoosphereError {
    /// Any error not covered by the other errors
    #[error("{0}")]
    Other(anyhow::Error),

    #[allow(missing_docs)]
    #[error("Network access required but network is currently offline")]
    NetworkOffline,

    #[allow(missing_docs)]
    #[error("No credentials configured")]
    NoCredentials,

    #[allow(missing_docs)]
    #[error("Missing configuration: {0}")]
    MissingConfiguration(&'static str),

    #[allow(missing_docs)]
    #[error("The provided authorization {0} is invalid: {1}")]
    InvalidAuthorization(Authorization, String),

    #[allow(missing_docs)]
    #[error("The gateway gave an unexpected or malformed response. {0}")]
    UnexpectedGatewayResponse(String),
}

impl From<anyhow::Error> for NoosphereError {
    fn from(error: anyhow::Error) -> Self {
        NoosphereError::Other(error)
    }
}