1use crate::{
2 document,
3 resolution::{self, DerefError},
4};
5use serde::Serialize;
6
7#[derive(Serialize)]
8pub enum ResolutionResult {
9 Success {
10 content: String,
11 metadata: resolution::Metadata,
12 document_metadata: document::Metadata,
13 },
14 Failure {
15 error: ErrorCode,
16 },
17}
18
19#[derive(Serialize)]
20#[serde(rename_all = "camelCase")]
21pub enum ErrorCode {
22 InvalidDid,
23 NotFound,
24 RepresentationNotSupported,
25 MethodNotSupported,
26 InternalError,
27}
28
29impl From<resolution::Error> for ErrorCode {
30 fn from(value: resolution::Error) -> Self {
31 match value {
32 resolution::Error::MethodNotSupported(_) => Self::MethodNotSupported,
33 resolution::Error::NotFound => Self::NotFound,
34 resolution::Error::NoRepresentation => Self::InternalError,
35 resolution::Error::RepresentationNotSupported(_) => Self::RepresentationNotSupported,
36 resolution::Error::InvalidData(_) => Self::InternalError,
37 resolution::Error::InvalidMethodSpecificId(_) => Self::InvalidDid,
38 resolution::Error::InvalidOptions => Self::InternalError,
39 resolution::Error::Internal(_) => Self::InternalError,
40 }
41 }
42}
43
44impl From<DerefError> for ErrorCode {
45 fn from(value: DerefError) -> Self {
46 match value {
47 DerefError::Resolution(e) => e.into(),
48 DerefError::MissingServiceEndpoint(_) => Self::InternalError,
49 DerefError::UnsupportedServiceEndpointMap => Self::InternalError,
50 DerefError::UnsupportedMultipleServiceEndpoints => Self::InternalError,
51 DerefError::ServiceEndpointConstructionFailed(_) => Self::InternalError,
52 DerefError::FragmentConflict => Self::InternalError,
53 DerefError::NullDereference => Self::InternalError,
54 DerefError::NotFound => Self::NotFound,
55 DerefError::ResourceNotFound(_) => Self::NotFound,
56 }
57 }
58}