diff --git a/src/http_client.rs b/src/http_client.rs index b87e20e..1f9dae3 100644 --- a/src/http_client.rs +++ b/src/http_client.rs @@ -24,11 +24,15 @@ pub struct HttpClient { } impl HttpClient { - pub fn new(base_url: &str, username: Option, password: Option) -> Self { + pub fn new( + base_url: &str, + username: Option, + password: Option, + ) -> Result { let user_agent_string = format!("{}/{}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION")); - Self { - base_url: if base_url.ends_with("/") { + Ok(Self { + base_url: if base_url.ends_with('/') { base_url[0..base_url.len() - 2].to_string() } else { base_url.to_string() @@ -38,8 +42,8 @@ impl HttpClient { client: reqwest::Client::builder() .user_agent(user_agent_string) .build() - .expect("Failed to build HTTP client"), - } + .map_err(|_| HttpClientError("Failed to build HTTP client".to_string()))?, + }) } pub async fn send_mtb_request(&self, mtb: &Mtb) -> Result { diff --git a/src/main.rs b/src/main.rs index ce90164..807d8a0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -33,7 +33,7 @@ async fn handle_record(payload: Mtb) -> Result { &CONFIG.dnpm_dip_uri, CONFIG.dnpm_dip_username.clone(), CONFIG.dnpm_dip_password.clone(), - ); + )?; if let Some(metadata) = &payload.metadata { if !metadata.model_project_consent.provisions.is_empty()