Mountain/Environment/Utility/
UriParsing.rs

1//! # URI Parsing Utilities
2//!
3//! Functions for parsing and converting URI/URL representations.
4
5use url::Url;
6use CommonLibrary::Error::CommonError::CommonError;
7
8/// Helper to get a `Url` from a `serde_json::Value` which is expected to be a
9/// `UriComponents` DTO from VS Code.
10pub fn GetURLFromURIComponentsDTO(URIDTO:&serde_json::Value) -> Result<Url, CommonError> {
11	// VS Code's UriComponents DTO often serializes to an object with a path,
12	// scheme, etc., but also includes a pre-formatted 'external' string version.
13	let URIString = URIDTO.get("external").and_then(serde_json::Value::as_str).ok_or_else(|| {
14		CommonError::InvalidArgument {
15			ArgumentName:"URIDTO".to_string(),
16			Reason:"Missing 'external' string field in UriComponents DTO".to_string(),
17		}
18	})?;
19
20	Url::parse(URIString).map_err(|Error| {
21		CommonError::InvalidArgument {
22			ArgumentName:"URIDTO.external".to_string(),
23			Reason:format!("Failed to parse URI string '{}': {}", URIString, Error),
24		}
25	})
26}