mirror of
https://github.com/DefectingCat/phthonus
synced 2025-07-15 16:41:32 +00:00
feat(axum): update unused constants
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
use std::{borrow::Cow, fmt::Display};
|
||||
use std::fmt::Display;
|
||||
|
||||
use axum::{
|
||||
extract::rejection::{FormRejection, JsonRejection},
|
||||
@ -20,13 +20,12 @@ pub enum AppError {
|
||||
AxumFormRejection(#[from] FormRejection),
|
||||
#[error(transparent)]
|
||||
AxumJsonRejection(#[from] JsonRejection),
|
||||
|
||||
// route
|
||||
// 路由通常错误 错误信息直接返回用户
|
||||
#[error("{0}")]
|
||||
AuthorizeFailed(Cow<'static, str>),
|
||||
#[error("{0}")]
|
||||
UserConflict(Cow<'static, str>),
|
||||
// #[error("{0}")]
|
||||
// AuthorizeFailed(Cow<'static, str>),
|
||||
// #[error("{0}")]
|
||||
// UserConflict(Cow<'static, str>),
|
||||
}
|
||||
|
||||
#[derive(Serialize_repr, Deserialize_repr, PartialEq, Debug)]
|
||||
@ -81,12 +80,11 @@ impl IntoResponse for AppError {
|
||||
ParameterIncorrect,
|
||||
self.to_string(),
|
||||
),
|
||||
|
||||
// route
|
||||
AppError::AuthorizeFailed(err) => {
|
||||
(StatusCode::UNAUTHORIZED, AuthorizeFailed, err.to_string())
|
||||
}
|
||||
AppError::UserConflict(err) => (StatusCode::CONFLICT, UserConflict, err.to_string()),
|
||||
// AppError::AuthorizeFailed(err) => {
|
||||
// (StatusCode::UNAUTHORIZED, AuthorizeFailed, err.to_string())
|
||||
// }
|
||||
// AppError::UserConflict(err) => (StatusCode::CONFLICT, UserConflict, err.to_string()),
|
||||
};
|
||||
let body = Json(json!({
|
||||
"code": code,
|
||||
|
@ -12,7 +12,10 @@ use tower_http::classify::ServerErrorsFailureClass;
|
||||
use tower_http::trace::TraceLayer;
|
||||
use tracing::{error, info, info_span, Span};
|
||||
|
||||
use crate::error::AppResult;
|
||||
use crate::{
|
||||
consts::{NAME, VERSION},
|
||||
error::AppResult,
|
||||
};
|
||||
|
||||
/// Middleware for adding version information to each response's headers.
|
||||
///
|
||||
@ -27,11 +30,8 @@ pub async fn add_version(
|
||||
) -> AppResult<impl IntoResponse> {
|
||||
let mut res = next.run(req).await;
|
||||
let headers = res.headers_mut();
|
||||
headers.append("Server", HeaderValue::from_static(env!("CARGO_PKG_NAME")));
|
||||
headers.append(
|
||||
"Phthonus-Version",
|
||||
HeaderValue::from_static(env!("CARGO_PKG_VERSION")),
|
||||
);
|
||||
headers.append("Server", HeaderValue::from_static(NAME));
|
||||
headers.append("Phthonus-Version", HeaderValue::from_static(VERSION));
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user