1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*use thiserror::Error;
use serde::Serialize;
use actix_http::StatusCode;
use actix_web::HttpResponse;
use actix_web::http::header::ContentType;
use autonomi::AddressParseError;
use autonomi::client::ConnectError;
use hex::FromHexError;
use crate::error::{CreateError, GetError, UpdateError};
#[derive(Error, Debug, Serialize)]
pub enum GraphError {
#[error("create error: {0}")]
CreateError(CreateError),
#[error("update error: {0}")]
UpdateError(UpdateError),
#[error("get error: {0}")]
GetError(GetError),
}
impl From<CreateError> for GraphError {
fn from(value: CreateError) -> Self {
Self::CreateError(value)
}
}
impl From<GetError> for GraphError {
fn from(value: GetError) -> Self {
Self::GetError(value)
}
}
impl From<foyer::Error> for GraphError {
fn from(value: foyer::Error) -> Self {
Self::GetError(value.into())
}
}
impl From<rmp_serde::decode::Error> for GraphError {
fn from(value: rmp_serde::decode::Error) -> Self {
Self::GetError(value.into())
}
}
impl From<ConnectError> for GraphError {
fn from(value: ConnectError) -> Self {
Self::GetError(value.into())
}
}
impl From<FromHexError> for GraphError {
fn from(value: FromHexError) -> Self {
Self::GetError(value.into())
}
}
impl From<AddressParseError> for GraphError {
fn from(value: AddressParseError) -> Self {
Self::GetError(value.into())
}
}
impl actix_web::ResponseError for GraphError {
fn status_code(&self) -> StatusCode {
match self {
GraphError::GetError(v) => v.status_code(),
GraphError::CreateError(v) => v.status_code(),
GraphError::UpdateError(v) => v.status_code(),
}
}
fn error_response(&self) -> HttpResponse {
HttpResponse::build(self.status_code())
.insert_header(ContentType::json())
.json(self)
}
}*/