Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
refactor(opensearch): Add Error Handling for Empty Query and Filters in Request (#5432)
Abhishek Kanojiab60933e310ab
diff --git a/crates/analytics/src/opensearch.rs b/crates/analytics/src/opensearch.rsindex 05f89b655c..1031c81544 100644--- a/crates/analytics/src/opensearch.rs+++ b/crates/analytics/src/opensearch.rs@@ -71,6 +71,8 @@ pub enum OpenSearchError {ConnectionError,#[error("Opensearch NON-200 response content: '{0}'")]ResponseNotOK(String),+ #[error("Opensearch bad request error")]+ BadRequestError(String),#[error("Opensearch response error")]ResponseError,#[error("Opensearch query building error")]@@ -98,6 +100,9 @@ impl ErrorSwitch<ApiErrorResponse> for OpenSearchError {"Connection error",None,)),+ Self::BadRequestError(response) => {+ ApiErrorResponse::BadRequest(ApiError::new("IR", 1, response.to_string(), None))+ }Self::ResponseNotOK(response) => ApiErrorResponse::InternalServerError(ApiError::new("IR",1,diff --git a/crates/analytics/src/search.rs b/crates/analytics/src/search.rsindex 4143a6df41..12ef7fb8d9 100644--- a/crates/analytics/src/search.rs+++ b/crates/analytics/src/search.rs@@ -16,6 +16,17 @@ pub async fn msearch_results(merchant_id: &common_utils::id_type::MerchantId,indexes: Vec<SearchIndex>,) -> CustomResult<Vec<GetSearchResponse>, OpenSearchError> {+ if req.query.trim().is_empty()+ && req+ .filters+ .as_ref()+ .map_or(true, |filters| filters.is_all_none())+ {+ return Err(OpenSearchError::BadRequestError(+ "Both query and filters are empty".to_string(),+ )+ .into());+ }let mut query_builder =OpenSearchQueryBuilder::new(OpenSearchQuery::Msearch(indexes.clone()), req.query);diff --git a/crates/api_models/src/analytics/search.rs b/crates/api_models/src/analytics/search.rsindex d1af00de56..f27af75936 100644--- a/crates/api_models/src/analytics/search.rs+++ b/crates/api_models/src/analytics/search.rs@@ -10,6 +10,15 @@ pub struct SearchFilters {pub customer_email: Option<Vec<HashedString<common_utils::pii::EmailStrategy>>>,pub search_tags: Option<Vec<HashedString<WithType>>>,}+impl SearchFilters {+ pub fn is_all_none(&self) -> bool {+ self.payment_method.is_none()+ && self.currency.is_none()+ && self.status.is_none()+ && self.customer_email.is_none()+ && self.search_tags.is_none()+ }+}#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]#[serde(rename_all = "camelCase")]