affinidi_did_resolver_traits/error.rs
1//! Error types for DID resolution.
2
3use affinidi_did_common::{DIDError, DocumentError};
4
5/// Error type for resolver failures.
6///
7/// Distinct from [`DIDError`] which covers parsing and type-level errors.
8/// `ResolverError` covers failures during the resolution process itself:
9/// network errors, invalid documents, unsupported methods, etc.
10#[derive(Debug, thiserror::Error)]
11pub enum ResolverError {
12 /// The DID method is not supported by this resolver.
13 #[error("Unsupported DID method: {0}")]
14 UnsupportedMethod(String),
15
16 /// Resolution failed due to a DID-level error (parsing, validation).
17 #[error("DID error: {0}")]
18 DIDError(#[from] DIDError),
19
20 /// Resolution failed due to a document-level error (key expansion, encoding).
21 #[error("Document error: {0}")]
22 DocumentError(#[from] DocumentError),
23
24 /// Resolution failed due to a network or IO error.
25 #[error("Resolution failed: {0}")]
26 ResolutionFailed(String),
27
28 /// The resolved document was malformed or invalid.
29 #[error("Invalid document: {0}")]
30 InvalidDocument(String),
31
32 /// Wraps an arbitrary error source.
33 #[error("{message}")]
34 Other {
35 message: String,
36 #[source]
37 source: Option<Box<dyn std::error::Error + Send + Sync>>,
38 },
39}
40
41impl ResolverError {
42 /// Create an `Other` error from any error type.
43 pub fn other(err: impl std::error::Error + Send + Sync + 'static) -> Self {
44 Self::Other {
45 message: err.to_string(),
46 source: Some(Box::new(err)),
47 }
48 }
49}