-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy patherror.rs
More file actions
34 lines (30 loc) · 1.1 KB
/
error.rs
File metadata and controls
34 lines (30 loc) · 1.1 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
use axum::{http::StatusCode, response::IntoResponse};
#[derive(Debug)]
/// Errors that the PbsService returns to client
pub enum PbsClientError {
NoResponse,
NoPayload,
Internal,
DecodeError(String),
}
impl PbsClientError {
pub fn status_code(&self) -> StatusCode {
match self {
PbsClientError::NoResponse => StatusCode::BAD_GATEWAY,
PbsClientError::NoPayload => StatusCode::BAD_GATEWAY,
PbsClientError::Internal => StatusCode::INTERNAL_SERVER_ERROR,
PbsClientError::DecodeError(_) => StatusCode::BAD_REQUEST,
}
}
}
impl IntoResponse for PbsClientError {
fn into_response(self) -> axum::response::Response {
let msg = match &self {
PbsClientError::NoResponse => "no response from relays".to_string(),
PbsClientError::NoPayload => "no payload from relays".to_string(),
PbsClientError::Internal => "internal server error".to_string(),
PbsClientError::DecodeError(e) => format!("error decoding request: {e}"),
};
(self.status_code(), msg).into_response()
}
}