2026-02-02 23:56:40 +01:00
|
|
|
//! Errores de la aplicación
|
|
|
|
|
//!
|
|
|
|
|
//! Este módulo re-exporta los errores del dominio y define utilidades
|
|
|
|
|
//! para conversión de errores de infraestructura.
|
2025-03-19 00:44:27 +01:00
|
|
|
|
2026-02-02 23:56:40 +01:00
|
|
|
// Re-exportar errores del dominio para compatibilidad
|
|
|
|
|
pub use crate::domain::errors::{DomainError, ErrorKind, Result};
|
2025-03-24 16:47:42 +01:00
|
|
|
|
2026-02-02 23:56:40 +01:00
|
|
|
// Re-exportar AppError desde interfaces para compatibilidad hacia atrás
|
|
|
|
|
// NOTA: El lugar canónico de AppError es ahora crate::interfaces::errors
|
2025-03-19 00:44:27 +01:00
|
|
|
|
2026-02-02 23:56:40 +01:00
|
|
|
// Macro para convertir errores específicos de infraestructura a DomainError
|
2025-03-19 00:44:27 +01:00
|
|
|
#[macro_export]
|
|
|
|
|
macro_rules! impl_from_error {
|
|
|
|
|
($error_type:ty, $entity_type:expr) => {
|
2026-02-02 23:56:40 +01:00
|
|
|
impl From<$error_type> for crate::domain::errors::DomainError {
|
2025-03-19 00:44:27 +01:00
|
|
|
fn from(err: $error_type) -> Self {
|
2026-02-02 23:56:40 +01:00
|
|
|
crate::domain::errors::DomainError {
|
|
|
|
|
kind: crate::domain::errors::ErrorKind::InternalError,
|
2025-03-19 00:44:27 +01:00
|
|
|
entity_type: $entity_type,
|
|
|
|
|
entity_id: None,
|
|
|
|
|
message: format!("{}", err),
|
|
|
|
|
source: Some(Box::new(err)),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-02 23:56:40 +01:00
|
|
|
// Implementaciones para errores de infraestructura (sqlx, serde_json)
|
2025-03-20 09:22:31 +01:00
|
|
|
impl_from_error!(serde_json::Error, "Serialization");
|
2025-04-02 03:43:44 +02:00
|
|
|
impl_from_error!(sqlx::Error, "Database");
|