improve error logging

This commit is contained in:
GW_MC
2025-12-31 18:03:42 +08:00
parent cb65d4e9f7
commit 46801fba99
2 changed files with 6 additions and 1 deletions

View File

@@ -1,14 +1,17 @@
use axum::response::IntoResponse; use axum::response::IntoResponse;
use sea_orm::DbErr; use sea_orm::DbErr;
use tracing::error;
use crate::errors::service_error::ServiceError; use crate::errors::service_error::ServiceError;
#[derive(Debug)]
pub enum ApiError { pub enum ApiError {
ServiceError(ServiceError), ServiceError(ServiceError),
} }
impl From<ServiceError> for ApiError { impl From<ServiceError> for ApiError {
fn from(err: ServiceError) -> Self { fn from(err: ServiceError) -> Self {
error!("Service error occurred: {:?}", err);
ApiError::ServiceError(err) ApiError::ServiceError(err)
} }
} }
@@ -21,6 +24,7 @@ impl From<DbErr> for ApiError {
impl IntoResponse for ApiError { impl IntoResponse for ApiError {
fn into_response(self) -> axum::response::Response { fn into_response(self) -> axum::response::Response {
error!("API error occurred: {:?}", self);
match self { match self {
ApiError::ServiceError(service_error) => service_error.into_response(), ApiError::ServiceError(service_error) => service_error.into_response(),
} }

View File

@@ -8,7 +8,7 @@ use agent_client::{
}, },
models::{ValidateAndReloadBody, ValidateBody, WriteConfigBody}, models::{ValidateAndReloadBody, ValidateBody, WriteConfigBody},
}; };
use tracing::warn; use tracing::{error, warn};
use crate::{configs::agent::AgentSettings, errors::service_error::ServiceError}; use crate::{configs::agent::AgentSettings, errors::service_error::ServiceError};
@@ -23,6 +23,7 @@ pub enum AgentError {
impl From<AgentError> for ServiceError { impl From<AgentError> for ServiceError {
fn from(err: AgentError) -> Self { fn from(err: AgentError) -> Self {
error!("Agent error occurred: {:?}", err);
match err { match err {
AgentError::ValidationFailed(_internal, user) => ServiceError::InternalError(user), AgentError::ValidationFailed(_internal, user) => ServiceError::InternalError(user),
AgentError::ApplicationFailed(_internal, user) => ServiceError::InternalError(user), AgentError::ApplicationFailed(_internal, user) => ServiceError::InternalError(user),