map_http_error_to_reason

Function map_http_error_to_reason 

Source
pub fn map_http_error_to_reason(status_code: u16) -> (&'static str, String)
Expand description

Map HTTP status code to condition reason and message.

This function converts HTTP status codes from Bindcar API responses into standardized Kubernetes condition reasons and human-readable messages.

§Arguments

  • status_code - HTTP status code (e.g., 400, 404, 500)

§Returns

A tuple of (reason, message):

  • reason - Constant from status_reasons module
  • message - Human-readable explanation of the error

§HTTP Code Mapping

HTTP CodeReasonMeaning
400BindcarBadRequestInvalid request format
401BindcarAuthFailedAuthentication required
403BindcarAuthFailedInsufficient permissions
404ZoneNotFoundResource not found
500BindcarInternalErrorInternal server error
501BindcarNotImplementedFeature not implemented
502GatewayErrorBad gateway
503GatewayErrorService unavailable
504GatewayErrorGateway timeout
OtherBindcarUnreachableUnexpected error

§Example

use bindy::http_errors::map_http_error_to_reason;

let (reason, message) = map_http_error_to_reason(404);
assert_eq!(reason, "ZoneNotFound");
assert!(message.contains("404"));

let (reason, message) = map_http_error_to_reason(503);
assert_eq!(reason, "GatewayError");
assert!(message.contains("503"));