reqwest_oauth1/
error.rs

1use thiserror::Error;
2
3/// Result type bound with `Error`.
4pub type Result<T> = std::result::Result<T, Error>;
5/// Result type bound with `SignError`.
6pub type SignResult<T> = std::result::Result<T, SignerError>;
7/// Result type bound with `TokenReaderError`.
8pub type TokenReaderResult<T> = std::result::Result<T, TokenReaderError>;
9
10/// The Error bundles the TokenReaderError, SignError, and reqwest::Error.
11#[derive(Error, Debug)]
12pub enum Error {
13    /// Represents TokenReaderError
14    #[error("token acquisition failed : {0}")]
15    TokenReader(#[from] TokenReaderError),
16    /// Represents SignError
17    #[error("OAuth sign failed : {0}")]
18    Signer(#[from] SignerError),
19    /// Represents reqwest::Error
20    #[error("request failed : {0}")]
21    Reqwest(#[from] reqwest::Error),
22}
23
24/// Errors about the signing with OAuth1 protocol.
25#[derive(Error, Debug, Clone)]
26pub enum SignerError {
27    /// Specified oauth_* parameter is not existed in the protocol specification.
28    #[error("unknown oauth parameter : {0}")]
29    UnknownParameter(String),
30    /// Specified oauth_* parameter is not configured via the reqwest::RequestBuilder::(query/form).
31    #[error("specified parameter {0} could not be configured via the reqwest parameters.")]
32    UnconfigurableParameter(String),
33    /// An invalid value is specified as the oauth_timestamp parameter.
34    #[error("invalid oauth_timestamp, must be u64, but {0} is not compatible.")]
35    InvalidTimestamp(String),
36    /// An invalid value is specified as the oauth_version parameter.
37    #[error("invalid oauth_version, must be 1.0 or just empty, but specified {0}.")]
38    InvalidVersion(String),
39}
40
41/// Errors thrown from token_reader.
42#[derive(Error, Debug, Clone)]
43pub enum TokenReaderError {
44    /// Returned value could not be parsed in the TokenReader.
45    #[error("the response has malformed format: key {0} is not found in response {1}")]
46    TokenKeyNotFound(&'static str, String),
47}