diff --git a/server/build.rs b/server/build.rs index 3da14bff39..ed104c9152 100644 --- a/server/build.rs +++ b/server/build.rs @@ -1,5 +1,4 @@ use std::error::Error; -use std::sync::Arc; #[cfg(feature = "hallucination-detection")] #[cfg(feature = "ner")] @@ -65,9 +64,6 @@ where P: AsRef, { let resp = ureq::AgentBuilder::new() - .tls_connector(Arc::new(native_tls::TlsConnector::new()?)) - .build() - .get(&url) .timeout(std::time::Duration::from_secs(300)) .call() .unwrap_or_else(|err| panic!("ERROR: Failed to download {}: {:?}", url, err)); diff --git a/server/src/bin/crawl-worker.rs b/server/src/bin/crawl-worker.rs index 55ff673962..ec8406b596 100644 --- a/server/src/bin/crawl-worker.rs +++ b/server/src/bin/crawl-worker.rs @@ -609,7 +609,11 @@ async fn crawl( let url = format!("{}/products.json?page={}", cleaned_url, cur_page); let response: ShopifyResponse = ureq::AgentBuilder::new() - .tls_connector(Arc::new(native_tls::TlsConnector::new()?)) + .tls_connector(Arc::new(native_tls::TlsConnector::new().map_err( + ServiceError::InternalServerError( + "Failed to acquire tls connection".to_string(), + ), + )?)) .build() .get(&url) .call() diff --git a/server/src/handlers/webhook_handler.rs b/server/src/handlers/webhook_handler.rs index b2cb03f91e..3de0eb9b97 100644 --- a/server/src/handlers/webhook_handler.rs +++ b/server/src/handlers/webhook_handler.rs @@ -1,5 +1,5 @@ -use std::sync::Arc; use std::str::FromStr; +use std::sync::Arc; use crate::data::models::Pool; use crate::data::models::RedisPool; diff --git a/server/src/operators/model_operator.rs b/server/src/operators/model_operator.rs index e8bf01401f..f48d7f9d8d 100644 --- a/server/src/operators/model_operator.rs +++ b/server/src/operators/model_operator.rs @@ -109,23 +109,25 @@ pub async fn get_dense_vector( web::block(move || { let embeddings_resp_a = ureq::AgentBuilder::new() - .tls_connector(Arc::new(native_tls::TlsConnector::new()?)) - .build() - .post(&format!( - "{}/embeddings?api-version=2023-05-15", - embedding_base_url - )) - .set("Authorization", &format!("Bearer {}", &embedding_api_key)) - .set("api-key", &embedding_api_key) - .set("Content-Type", "application/json") - .send_json(serde_json::to_value(parameters).unwrap()) - .map_err(|e| { - ServiceError::InternalServerError(format!( - "Could not get embeddings from server: {:?}, {:?}", - e, - e.to_string() + .tls_connector(Arc::new(native_tls::TlsConnector::new().map_err(|_| { + ServiceError::InternalServerError("Failed to acquire tls connection".to_string()) + })?)) + .build() + .post(&format!( + "{}/embeddings?api-version=2023-05-15", + embedding_base_url )) - })?; + .set("Authorization", &format!("Bearer {}", &embedding_api_key)) + .set("api-key", &embedding_api_key) + .set("Content-Type", "application/json") + .send_json(serde_json::to_value(parameters).unwrap()) + .map_err(|e| { + ServiceError::InternalServerError(format!( + "Could not get embeddings from server: {:?}, {:?}", + e, + e.to_string() + )) + })?; let embeddings_resp = embeddings_resp_a .into_json::() @@ -211,7 +213,9 @@ pub async fn get_sparse_vector( web::block(move || { let mut sparse_vectors = ureq::AgentBuilder::new() - .tls_connector(Arc::new(native_tls::TlsConnector::new()?)) + .tls_connector(Arc::new(native_tls::TlsConnector::new().map_err(|_| { + ServiceError::InternalServerError("Failed to acquire tls connection".to_string()) + })?)) .build() .post(&embedding_server_call) .set("Content-Type", "application/json") @@ -897,7 +901,11 @@ pub async fn cross_encoder( // Assume cohere let reranker_model_name = dataset_config.RERANKER_MODEL_NAME.clone(); let resp = ureq::AgentBuilder::new() - .tls_connector(Arc::new(native_tls::TlsConnector::new()?)) + .tls_connector(Arc::new(native_tls::TlsConnector::new().map_err(|_| { + ServiceError::InternalServerError( + "Failed to acquire tls connection".to_string(), + ) + })?)) .build() .post(&embedding_server_call) .set("Content-Type", "application/json") @@ -929,7 +937,11 @@ pub async fn cross_encoder( }); } else { let resp = ureq::AgentBuilder::new() - .tls_connector(Arc::new(native_tls::TlsConnector::new()?)) + .tls_connector(Arc::new(native_tls::TlsConnector::new().map_err(|_| { + ServiceError::InternalServerError( + "Failed to acquire tls connection".to_string(), + ) + })?)) .build() .post(&embedding_server_call) .set("Content-Type", "application/json")