mirror of
https://github.com/pcvolkmer/mv64e-kafka-to-rest-gateway
synced 2025-09-13 17:22:52 +00:00
refactor: remove expect()
This commit is contained in:
@@ -24,11 +24,15 @@ pub struct HttpClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl HttpClient {
|
impl HttpClient {
|
||||||
pub fn new(base_url: &str, username: Option<String>, password: Option<String>) -> Self {
|
pub fn new(
|
||||||
|
base_url: &str,
|
||||||
|
username: Option<String>,
|
||||||
|
password: Option<String>,
|
||||||
|
) -> Result<Self, HttpClientError> {
|
||||||
let user_agent_string = format!("{}/{}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"));
|
let user_agent_string = format!("{}/{}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"));
|
||||||
|
|
||||||
Self {
|
Ok(Self {
|
||||||
base_url: if base_url.ends_with("/") {
|
base_url: if base_url.ends_with('/') {
|
||||||
base_url[0..base_url.len() - 2].to_string()
|
base_url[0..base_url.len() - 2].to_string()
|
||||||
} else {
|
} else {
|
||||||
base_url.to_string()
|
base_url.to_string()
|
||||||
@@ -38,8 +42,8 @@ impl HttpClient {
|
|||||||
client: reqwest::Client::builder()
|
client: reqwest::Client::builder()
|
||||||
.user_agent(user_agent_string)
|
.user_agent(user_agent_string)
|
||||||
.build()
|
.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<HttpResponse, HttpClientError> {
|
pub async fn send_mtb_request(&self, mtb: &Mtb) -> Result<HttpResponse, HttpClientError> {
|
||||||
|
@@ -33,7 +33,7 @@ async fn handle_record(payload: Mtb) -> Result<HttpResponse, HttpClientError> {
|
|||||||
&CONFIG.dnpm_dip_uri,
|
&CONFIG.dnpm_dip_uri,
|
||||||
CONFIG.dnpm_dip_username.clone(),
|
CONFIG.dnpm_dip_username.clone(),
|
||||||
CONFIG.dnpm_dip_password.clone(),
|
CONFIG.dnpm_dip_password.clone(),
|
||||||
);
|
)?;
|
||||||
|
|
||||||
if let Some(metadata) = &payload.metadata {
|
if let Some(metadata) = &payload.metadata {
|
||||||
if !metadata.model_project_consent.provisions.is_empty()
|
if !metadata.model_project_consent.provisions.is_empty()
|
||||||
|
Reference in New Issue
Block a user