global: snapshot

This commit is contained in:
nym21
2025-11-09 11:25:13 +01:00
parent e77fe0253e
commit dc2e847f58
30 changed files with 521 additions and 497 deletions
+16 -1
View File
@@ -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),
}
}
}