Files
One-KVM/src/web/error.rs
2026-05-01 17:31:04 +08:00

32 lines
739 B
Rust

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()
}
}