Backend Error Handling
Forbidden
.unwrap()in request paths (handlers, repos, services called from handlers).expect()in request pathspanic!()anywhere except tests
Allowed
.unwrap_or(),.unwrap_or_else(),.unwrap_or_default().unwrap()/.expect()ONLY in tests (#[cfg(test)])?operator with proper error conversion
Error Type
All errors must use AppError from crate::error:
- AppError::BadRequest(msg) — 400
- AppError::Unauthorized(msg) — 401
- AppError::Forbidden(msg) — 403
- AppError::NotFound(msg) — 404
- AppError::Conflict(msg) — 409
- AppError::Internal(anyhow) — 500
Use log_internal("context", e) to convert external errors with full cause chain logging.
Logging
- Mandatory
tracing::info!for: factura created/validated, escandallo changes, stock updates, precio changes - Use
tracing::debug!for routine operations - Use
tracing::error!only vialog_internalor explicit error paths