backend sliced by modules
This commit is contained in:
+26
-12
@@ -42,45 +42,59 @@ impl IntoResponse for AppError {
|
||||
AppError::Internal => "internal",
|
||||
};
|
||||
|
||||
// Метрики остаются как были
|
||||
metrics::counter!("app_errors_total", "type" => error_type).increment(1);
|
||||
|
||||
let (status, error_message) = match &self {
|
||||
AppError::UserNotFound => {
|
||||
warn!("Attempted action for non-existent user");
|
||||
warn!(error_type, "Attempted action for non-existent user");
|
||||
(StatusCode::NOT_FOUND, "User profile not found".to_string())
|
||||
}
|
||||
AppError::TrialAlreadyUsed => {
|
||||
warn!("Attempted to activate exhausted trial");
|
||||
warn!(error_type, "Attempted to activate exhausted trial");
|
||||
(StatusCode::CONFLICT, "Trial already used".to_string())
|
||||
}
|
||||
AppError::Database(e) => {
|
||||
error!("DB Execution Error: {:?}", e);
|
||||
// Логируем саму ошибку базы как отдельное поле для поиска
|
||||
error!(error_type, db_error = ?e, "Database execution failure");
|
||||
(
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
"Internal server database error".to_string(),
|
||||
)
|
||||
}
|
||||
AppError::Transaction(msg) => {
|
||||
error!("Transaction commit failed: {}", msg);
|
||||
error!(error_type, details = %msg, "Transaction commit failed");
|
||||
(
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
"Transaction processing failed".to_string(),
|
||||
)
|
||||
}
|
||||
AppError::Redis(e) => {
|
||||
error!("Redis Error: {:?}", e);
|
||||
error!(error_type, redis_error = ?e, "Redis connection/command failure");
|
||||
(
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
"Internal server error".to_string(),
|
||||
)
|
||||
}
|
||||
AppError::Unauthorized(msg) => (StatusCode::UNAUTHORIZED, msg.clone()),
|
||||
AppError::NotFound(msg) => (StatusCode::NOT_FOUND, msg.clone()),
|
||||
AppError::BusinessLogic(msg) => (StatusCode::BAD_REQUEST, msg.clone()),
|
||||
AppError::Internal => (
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
"Critical failure".to_string(),
|
||||
),
|
||||
AppError::Unauthorized(msg) => {
|
||||
warn!(error_type, details = %msg, "Unauthorized access blocked");
|
||||
(StatusCode::UNAUTHORIZED, msg.clone())
|
||||
}
|
||||
AppError::NotFound(msg) => {
|
||||
warn!(error_type, details = %msg, "Resource not found");
|
||||
(StatusCode::NOT_FOUND, msg.clone())
|
||||
}
|
||||
AppError::BusinessLogic(msg) => {
|
||||
warn!(error_type, details = %msg, "Business logic violation");
|
||||
(StatusCode::BAD_REQUEST, msg.clone())
|
||||
}
|
||||
AppError::Internal => {
|
||||
error!(error_type, "Critical internal failure");
|
||||
(
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
"Critical failure".to_string(),
|
||||
)
|
||||
}
|
||||
};
|
||||
|
||||
let body = Json(json!({
|
||||
|
||||
Reference in New Issue
Block a user