feat: Add list_rating_plans error handling, dead_code attributes, and refactor monitoring/models

- Add error mapping to list_rating_plans in engine.rs
- Add dead_code attributes to get/list_map/deactivate methods in rating_plans_repo and row_to_plan function
- Add list method to RatingPlansRepo returning Vec<RatingPlan>
- Add dead_code attribute to validate_imsi in helpers
- Add UsageBlocked and ConfigurationError variants to ChargingError with Display/IntoResponse implementations
- Add Default
This commit is contained in:
nutcas3
2026-04-25 02:14:10 +03:00
parent 8b86e55226
commit 1ee156af75
10 changed files with 55 additions and 28 deletions
@@ -68,6 +68,7 @@ pub fn validate_bytes(bytes: u64) -> ChargingResult<()> {
Ok(())
}
#[allow(dead_code)]
pub fn validate_imsi(imsi: &str) -> ChargingResult<()> {
if imsi.is_empty() {
return Err(ChargingError::InvalidInput("IMSI cannot be empty".to_string()));
+7
View File
@@ -10,8 +10,11 @@ pub enum ChargingError {
SubscriberNotFound(String),
RatingPlanNotFound(String),
InsufficientCredit { available: u64, requested: u64 },
UsageBlocked(String),
InvalidInput(String),
SerializationError(String),
#[allow(dead_code)]
ConfigurationError(String),
InternalError(String),
}
@@ -25,8 +28,10 @@ impl fmt::Display for ChargingError {
ChargingError::InsufficientCredit { available, requested } => {
write!(f, "Insufficient credit: available={}, requested={}", available, requested)
}
ChargingError::UsageBlocked(reason) => write!(f, "Usage blocked: {}", reason),
ChargingError::InvalidInput(msg) => write!(f, "Invalid input: {}", msg),
ChargingError::SerializationError(msg) => write!(f, "Serialization error: {}", msg),
ChargingError::ConfigurationError(msg) => write!(f, "Configuration error: {}", msg),
ChargingError::InternalError(msg) => write!(f, "Internal error: {}", msg),
}
}
@@ -44,8 +49,10 @@ impl IntoResponse for ChargingError {
ChargingError::InsufficientCredit { available, requested } => {
(StatusCode::PAYMENT_REQUIRED, format!("Insufficient credit: available={}, requested={}", available, requested))
}
ChargingError::UsageBlocked(reason) => (StatusCode::FORBIDDEN, reason),
ChargingError::InvalidInput(msg) => (StatusCode::BAD_REQUEST, msg),
ChargingError::SerializationError(msg) => (StatusCode::INTERNAL_SERVER_ERROR, msg),
ChargingError::ConfigurationError(msg) => (StatusCode::INTERNAL_SERVER_ERROR, msg),
ChargingError::InternalError(msg) => (StatusCode::INTERNAL_SERVER_ERROR, msg),
};