diff --git a/src/error.rs b/src/error.rs index 510ce21..c7513d8 100644 --- a/src/error.rs +++ b/src/error.rs @@ -4,6 +4,7 @@ use axum::response::{IntoResponse, Response}; pub enum AppError { IpNotFound, InvalidIp, + MissingClientIp, DbLookupFailed, } @@ -12,6 +13,7 @@ impl IntoResponse for AppError { let (status, message) = match self { Self::IpNotFound => (StatusCode::NOT_FOUND, "IP not found in database"), Self::InvalidIp => (StatusCode::BAD_REQUEST, "Invalid IP address"), + Self::MissingClientIp => (StatusCode::BAD_REQUEST, "Missing client IP address"), Self::DbLookupFailed => (StatusCode::INTERNAL_SERVER_ERROR, "Database lookup failed"), }; (status, message).into_response() diff --git a/src/handlers.rs b/src/handlers.rs index 823cf03..b46b378 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -52,7 +52,7 @@ fn extract_client_ip(headers: &HeaderMap) -> Result { .get("CF-Connecting-IP") .and_then(|v| v.to_str().ok()) .and_then(|s| s.trim().parse().ok()) - .ok_or(AppError::IpNotFound) + .ok_or(AppError::MissingClientIp) } fn lookup_ip(db: &SharedDb, ip: IpAddr) -> Result { diff --git a/tests/integration.rs b/tests/integration.rs index 0ef066c..9071a77 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -231,7 +231,7 @@ async fn root_without_cf_header_returns_error() { )], ) .await; - assert_eq!(status, StatusCode::NOT_FOUND); + assert_eq!(status, StatusCode::BAD_REQUEST); } #[tokio::test]