diff --git a/apps/charging-engine/src/errors/helpers.rs b/apps/charging-engine/src/errors/helpers.rs index ee2606e..caa3fe1 100644 --- a/apps/charging-engine/src/errors/helpers.rs +++ b/apps/charging-engine/src/errors/helpers.rs @@ -1,11 +1,20 @@ use anyhow::Context; +use super::types::ChargingError; + pub type ChargingResult = Result; pub trait ErrorContext { fn with_context(self, msg: &str) -> ChargingResult; } +impl ErrorContext for anyhow::Result { + fn with_context(self, msg: &str) -> ChargingResult { + self.map_err(|e| ChargingError::InternalError(format!("{}: {}", msg, e))) + .map_err(|e| e.into()) + } +} + impl ErrorContext for Result where E: Into,