-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy patherror.rs
More file actions
57 lines (48 loc) · 1.85 KB
/
Copy patherror.rs
File metadata and controls
57 lines (48 loc) · 1.85 KB
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
use alloy::hex;
use axum::{
http::StatusCode,
response::{IntoResponse, Response},
};
use thiserror::Error;
#[derive(Debug, Error)]
pub enum SignerModuleError {
#[error("unauthorized")]
Unauthorized,
#[error("signer error: {0}")]
SignerError(#[from] alloy::signers::Error),
#[error("unknown consensus signer: 0x{}", hex::encode(.0))]
UnknownConsensusSigner(Vec<u8>),
#[error("unknown proxy signer: 0x{}", hex::encode(.0))]
UnknownProxySigner(Vec<u8>),
#[error("Dirk communication error: {0}")]
DirkCommunicationError(String),
#[error("Dirk signer does not support this operation")]
DirkNotSupported,
#[error("internal error: {0}")]
Internal(String),
#[error("rate limited for {0} more seconds")]
RateLimited(f64),
}
impl IntoResponse for SignerModuleError {
fn into_response(self) -> Response {
match self {
SignerModuleError::Unauthorized => (StatusCode::UNAUTHORIZED, self.to_string()),
SignerModuleError::UnknownConsensusSigner(_) => {
(StatusCode::NOT_FOUND, self.to_string())
}
SignerModuleError::UnknownProxySigner(_) => (StatusCode::NOT_FOUND, self.to_string()),
SignerModuleError::DirkCommunicationError(_) => {
(StatusCode::BAD_GATEWAY, self.to_string())
}
SignerModuleError::DirkNotSupported => (StatusCode::BAD_REQUEST, self.to_string()),
SignerModuleError::Internal(_) => {
(StatusCode::INTERNAL_SERVER_ERROR, self.to_string())
}
SignerModuleError::SignerError(err) => (StatusCode::BAD_REQUEST, err.to_string()),
SignerModuleError::RateLimited(duration) => {
(StatusCode::TOO_MANY_REQUESTS, format!("rate limited for {duration:?}"))
}
}
.into_response()
}
}