1#[derive(thiserror::Error, Debug)]
3pub enum Error {
4 #[error("methodNotSupported")]
6 MethodNotSupported(String),
7
8 #[error("invalidDid")]
11 InvalidDid(String),
12
13 #[error("notFound")]
16 NotFound(String),
17
18 #[error("representationNotSupported")]
21 RepresentationNotSupported(String),
22
23 #[error("invalidDidUrl")]
25 InvalidDidUrl(String),
26
27 #[error("invalidPublicKeyLength")]
31 InvalidPublicKeyLength(String),
32
33 #[error("invalidPublicKey")]
35 InvalidPublicKey(String),
36
37 #[error("unsupportedPublicKeyType")]
39 UnsupportedPublicKeyType(String),
40
41 #[error(transparent)]
43 Other(#[from] anyhow::Error),
44}
45
46impl Error {
47 #[must_use]
49 pub fn code(&self) -> String {
50 self.to_string()
51 }
52
53 #[must_use]
55 pub fn message(&self) -> String {
56 match self {
57 Self::MethodNotSupported(msg)
58 | Self::InvalidDid(msg)
59 | Self::NotFound(msg)
60 | Self::InvalidDidUrl(msg)
61 | Self::RepresentationNotSupported(msg)
62 | Self::InvalidPublicKeyLength(msg)
63 | Self::InvalidPublicKey(msg)
64 | Self::UnsupportedPublicKeyType(msg) => msg.clone(),
65 Self::Other(err) => err.to_string(),
66 }
67 }
68}
69
70#[cfg(test)]
77mod test {
78 use super::*;
79
80 #[test]
81 fn error_code() {
82 let err = Error::MethodNotSupported("Method not supported".into());
83 assert_eq!(err.message(), "Method not supported");
84 }
85}