mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-06-14 19:51:58 +08:00
refactor: 删除部分多余的代码和注释
This commit is contained in:
31
src/web/error.rs
Normal file
31
src/web/error.rs
Normal file
@@ -0,0 +1,31 @@
|
||||
use crate::error::AppError;
|
||||
use axum::{
|
||||
http::StatusCode,
|
||||
response::{IntoResponse, Response},
|
||||
Json,
|
||||
};
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct ErrorResponse {
|
||||
pub success: bool,
|
||||
pub message: String,
|
||||
}
|
||||
|
||||
impl IntoResponse for AppError {
|
||||
fn into_response(self) -> Response {
|
||||
let body = ErrorResponse {
|
||||
success: false,
|
||||
message: self.to_string(),
|
||||
};
|
||||
|
||||
tracing::error!(
|
||||
error_type = std::any::type_name_of_val(&self),
|
||||
error_message = %body.message,
|
||||
"Request failed"
|
||||
);
|
||||
|
||||
// Always return 200 OK - success/failure is indicated by the success field
|
||||
(StatusCode::OK, Json(body)).into_response()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user