Factorize RON error response for not authorized content
This commit is contained in:
parent
f23fd2b832
commit
f31167dd95
2 changed files with 20 additions and 38 deletions
|
|
@ -1,12 +1,14 @@
|
|||
use axum::{
|
||||
body::Bytes,
|
||||
http::{HeaderValue, StatusCode, header},
|
||||
response::{IntoResponse, Response},
|
||||
response::{ErrorResponse, IntoResponse, Response},
|
||||
};
|
||||
use common::ron_api;
|
||||
use ron::de::from_bytes;
|
||||
use serde::{Serialize, de::DeserializeOwned};
|
||||
|
||||
use crate::consts;
|
||||
|
||||
pub const RON_CONTENT_TYPE: HeaderValue = HeaderValue::from_static("application/ron");
|
||||
|
||||
#[derive(Debug, Serialize, Clone)]
|
||||
|
|
@ -42,6 +44,13 @@ pub fn ron_error(status: StatusCode, message: &str) -> impl IntoResponse {
|
|||
)
|
||||
}
|
||||
|
||||
pub fn ron_error_not_autorized() -> ErrorResponse {
|
||||
ErrorResponse::from(ron_error(
|
||||
StatusCode::UNAUTHORIZED,
|
||||
consts::NOT_AUTHORIZED_MESSAGE,
|
||||
))
|
||||
}
|
||||
|
||||
pub fn ron_response_ok<T>(ron: T) -> impl IntoResponse
|
||||
where
|
||||
T: Serialize,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue