Expand description
§Structured Error Types
This module provides structured error types for common scenarios in data fetching
and provider operations. Using structured errors instead of generic String errors
provides better error handling, debugging, and type safety.
§Examples
§Using ProviderError for general provider failures:
use dioxus_provider::errors::ProviderError;
#[provider]
async fn fetch_user(user_id: u32) -> Result<User, ProviderError> {
if user_id == 0 {
return Err(ProviderError::InvalidInput("User ID cannot be zero".to_string()));
}
let response = api_call(user_id).await
.map_err(|e| ProviderError::ExternalService {
service: "UserAPI".to_string(),
error: e.to_string(),
})?;
Ok(response)
}§Using custom domain-specific errors:
use dioxus_provider::errors::ProviderError;
use thiserror::Error;
#[derive(Error, Debug, Clone, PartialEq)]
pub enum UserError {
#[error("User not found: {id}")]
NotFound { id: u32 },
#[error("User is suspended: {reason}")]
Suspended { reason: String },
#[error("Permission denied for user {user_id}")]
PermissionDenied { user_id: u32 },
#[error("Provider error: {0}")]
Provider(#[from] ProviderError),
}
#[provider]
async fn fetch_user_profile(user_id: u32) -> Result<UserProfile, UserError> {
// Implementation
}Enums§
- ApiError
- Errors specific to API operations
- Database
Error - Errors specific to database operations
- Provider
Error - Common error types for provider operations
- User
Error - Errors specific to user operations
Type Aliases§
- ApiResult
- Convenience type alias for Results with ApiError
- Database
Result - Convenience type alias for Results with DatabaseError
- Provider
Result - Convenience type alias for Results with ProviderError
- User
Result - Convenience type alias for Results with UserError