#![allow(missing_docs)] use http_handle::ServerError; /// Entry point for the Http Handle error handling examples. /// /// This function runs various examples demonstrating error creation, conversion, /// and handling for different scenarios in the Http Handle library. /// /// # Errors /// /// Returns an error if any of the example functions fail. fn main() -> Result<(), Box> { println!("\n๐Ÿงช Http Handle Error Handling Examples\n"); io_error_example()?; invalid_request_error_example()?; not_found_error_example()?; forbidden_error_example()?; custom_error_example()?; println!( "\n๐ŸŽ‰ All error handling examples completed successfully!" ); Ok(()) } /// Demonstrates handling of I/O errors. fn io_error_example() -> Result<(), ServerError> { println!("๐Ÿฆ€ I/O Error Example"); println!("---------------------------------------------"); let io_error = std::io::Error::new( std::io::ErrorKind::NotFound, "File not found", ); let server_error = ServerError::from(io_error); println!(" โœ… Created I/O Error: {}", server_error); Ok(()) } /// Demonstrates handling of invalid request errors. fn invalid_request_error_example() -> Result<(), ServerError> { println!("\n๐Ÿฆ€ Invalid Request Error Example"); println!("---------------------------------------------"); let error = ServerError::invalid_request("Missing HTTP method"); println!(" โœ… Created Invalid Request Error: {}", error); Ok(()) } /// Demonstrates handling of file not found errors. fn not_found_error_example() -> Result<(), ServerError> { println!("\n๐Ÿฆ€ File Not Found Error Example"); println!("---------------------------------------------"); let error = ServerError::not_found("/nonexistent.html"); println!(" โœ… Created Not Found Error: {}", error); Ok(()) } /// Demonstrates handling of forbidden access errors. fn forbidden_error_example() -> Result<(), ServerError> { println!("\n๐Ÿฆ€ Forbidden Access Error Example"); println!("---------------------------------------------"); let error = ServerError::forbidden("Access denied to sensitive file"); println!(" โœ… Created Forbidden Error: {}", error); Ok(()) } /// Demonstrates handling of custom errors. fn custom_error_example() -> Result<(), ServerError> { println!("\n๐Ÿฆ€ Custom Error Example"); println!("---------------------------------------------"); let error: ServerError = "Unexpected error".into(); println!(" โœ… Created Custom Error: {}", error); Ok(()) }