Cleaning
This commit is contained in:
parent
198bff6e4a
commit
6f014ef238
19 changed files with 118 additions and 81 deletions
|
|
@ -18,13 +18,15 @@ pub struct RonError {
|
|||
|
||||
impl axum::response::IntoResponse for RonError {
|
||||
fn into_response(self) -> Response {
|
||||
let ron_as_str = ron_api::to_string(&self);
|
||||
(
|
||||
StatusCode::BAD_REQUEST,
|
||||
[(header::CONTENT_TYPE, RON_CONTENT_TYPE)],
|
||||
ron_as_str,
|
||||
)
|
||||
.into_response()
|
||||
match ron_api::to_string(&self) {
|
||||
Ok(ron_as_str) => (
|
||||
StatusCode::BAD_REQUEST,
|
||||
[(header::CONTENT_TYPE, RON_CONTENT_TYPE)],
|
||||
ron_as_str,
|
||||
)
|
||||
.into_response(),
|
||||
Err(error) => (StatusCode::INTERNAL_SERVER_ERROR, error.to_string()).into_response(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -44,7 +46,7 @@ pub fn ron_error(status: StatusCode, message: &str) -> impl IntoResponse {
|
|||
)
|
||||
}
|
||||
|
||||
pub fn ron_error_not_autorized() -> ErrorResponse {
|
||||
pub fn ron_error_not_authorized() -> ErrorResponse {
|
||||
ErrorResponse::from(ron_error(
|
||||
StatusCode::UNAUTHORIZED,
|
||||
consts::NOT_AUTHORIZED_MESSAGE,
|
||||
|
|
@ -58,16 +60,19 @@ where
|
|||
ron_response(StatusCode::OK, ron)
|
||||
}
|
||||
|
||||
pub fn ron_response<T>(status: StatusCode, ron: T) -> impl IntoResponse
|
||||
pub fn ron_response<T>(status: StatusCode, ron: T) -> Response
|
||||
where
|
||||
T: Serialize,
|
||||
{
|
||||
let ron_as_str = ron_api::to_string(&ron);
|
||||
(
|
||||
status,
|
||||
[(header::CONTENT_TYPE, RON_CONTENT_TYPE)],
|
||||
ron_as_str,
|
||||
)
|
||||
match ron_api::to_string(&ron) {
|
||||
Ok(ron_as_str) => (
|
||||
status,
|
||||
[(header::CONTENT_TYPE, RON_CONTENT_TYPE)],
|
||||
ron_as_str,
|
||||
)
|
||||
.into_response(),
|
||||
Err(error) => (StatusCode::INTERNAL_SERVER_ERROR, error.to_string()).into_response(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse_body<T>(body: Bytes) -> Result<T, RonError>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue