Function sanitize_url_for_error

Source
pub fn sanitize_url_for_error(url: &str) -> String
Expand description

Sanitizes a URL for error messages by only showing scheme, host, and port

This function is more aggressive than sanitize_url because it completely redacts the path, query parameters, and fragments. This prevents leaking API keys that are commonly embedded in RPC URL paths (e.g., Infura, Alchemy).

ยงExamples

use openzeppelin_relayer::utils::sanitize_url_for_error;

// API key in path is redacted
assert_eq!(
    sanitize_url_for_error("https://mainnet.infura.io/v3/SECRET_KEY"),
    "https://mainnet.infura.io/[path redacted]"
);

// Query parameters are also redacted
assert_eq!(
    sanitize_url_for_error("https://api.example.com?apikey=secret"),
    "https://api.example.com/[path redacted]"
);

// Invalid URLs show a safe placeholder
assert_eq!(sanitize_url_for_error("not-a-url"), "[invalid URL]");