Applications should gracefully handle different network connectivity states and provide appropriate feedback to users. Follow these guidelines: 1. **Check connectivity state before network operations** - Always verify if the application is in offline mode before attempting network requests
Applications should gracefully handle different network connectivity states and provide appropriate feedback to users. Follow these guidelines:
Example for offline handling:
if network_settings.connectivity.is_offline() {
writeln!(
printer.stderr(),
"{}",
format_args!(
"{}{} Operation is not possible because network connectivity is disabled (i.e., with `--offline`)",
// formatting details
)
)?;
return Ok(ExitStatus::Failure);
}
Example for checking cache before network request:
// Check if we already have the resource locally before making a network request
if let (Some(rev), Some(db)) = (self.git.precise(), &maybe_db) {
if db.contains(rev) {
debug!("Using existing Git source `{}`", self.git.repository());
return Ok((maybe_db.unwrap(), rev, None));
}
}
// Only make network request if needed
// Handle different status codes appropriately
let decision = status_code_strategy.handle_status_code(status_code, index, capabilities);
Enter the URL of a public GitHub repository