mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-21 07:58:11 -07:00
global: snapshot
This commit is contained in:
@@ -1,8 +1,13 @@
|
||||
use axum::http::StatusCode;
|
||||
use axum::{http::StatusCode, response::Response};
|
||||
use brk_error::{Error, Result};
|
||||
|
||||
use crate::extended::ResponseExtended;
|
||||
|
||||
pub trait ResultExtended<T> {
|
||||
fn with_status(self) -> Result<T, (StatusCode, String)>;
|
||||
fn to_json_response(self, etag: &str) -> Response
|
||||
where
|
||||
T: sonic_rs::Serialize;
|
||||
}
|
||||
|
||||
impl<T> ResultExtended<T> for Result<T> {
|
||||
@@ -21,4 +26,14 @@ impl<T> ResultExtended<T> for Result<T> {
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn to_json_response(self, etag: &str) -> Response
|
||||
where
|
||||
T: sonic_rs::Serialize,
|
||||
{
|
||||
match self.with_status() {
|
||||
Ok(value) => Response::new_json(&value, etag),
|
||||
Err((status, message)) => Response::new_json_with(status, &message, etag),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user