diff --git a/web/Rust/axum/src/error.rs b/web/Rust/axum/src/error.rs index 3147417..b92b11d 100644 --- a/web/Rust/axum/src/error.rs +++ b/web/Rust/axum/src/error.rs @@ -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, diff --git a/web/Rust/axum/src/middlewares/mod.rs b/web/Rust/axum/src/middlewares/mod.rs index 3880d6a..78c2c02 100644 --- a/web/Rust/axum/src/middlewares/mod.rs +++ b/web/Rust/axum/src/middlewares/mod.rs @@ -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 { 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) }