cloud_file_signer/
error.rs

1//! Errors that can occur while signing a URL.
2
3use std::fmt::{Display, Formatter};
4
5/// An error that occurred while signing a URL.
6#[derive(Debug, Clone, PartialEq, Eq, Hash)]
7pub struct SignerError {
8    kind: SignerErrorKind,
9    message: String,
10}
11
12impl SignerError {
13    fn new(kind: SignerErrorKind, message: String) -> Self {
14        Self { kind, message }
15    }
16
17    /// Return the kind of error.
18    #[must_use]
19    pub fn kind(&self) -> SignerErrorKind {
20        self.kind
21    }
22
23    /// Return the error message.
24    #[must_use]
25    pub fn message(&self) -> &str {
26        &self.message
27    }
28
29    /// Create a new `CloudUriParseError`.
30    pub fn uri_parse_error(message: impl Into<String>) -> Self {
31        Self::new(SignerErrorKind::CloudUriParseError, message.into())
32    }
33
34    /// Create a new `PermissionNotSupported` error.
35    pub fn permission_not_supported(message: impl Into<String>) -> Self {
36        Self::new(SignerErrorKind::PermissionNotSupported, message.into())
37    }
38
39    /// Create a new Other error.
40    pub fn other_error(message: impl Into<String>) -> Self {
41        Self::new(SignerErrorKind::Other, message.into())
42    }
43}
44
45/// The kind of error that occurred while signing a URL.
46#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
47pub enum SignerErrorKind {
48    /// The URI of the object could not be parsed.
49    CloudUriParseError,
50    /// The requested permission is not supported by the signer.
51    PermissionNotSupported,
52    /// Some other error occurred.
53    Other,
54}
55
56impl Display for SignerError {
57    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
58        write!(f, "SignerError")
59    }
60}
61
62impl std::error::Error for SignerError {}