Skip to content

Commit

Permalink
fix: use match and logger
Browse files Browse the repository at this point in the history
  • Loading branch information
apoorvdixit88 committed Jan 16, 2024
1 parent 4783970 commit 1ca7d36
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions crates/router/src/utils/user/sample_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub async fn generate_sample_data(

let business_label_default = merchant_parsed_details.first().map(|x| x.business.clone());

let profile_id = crate::core::utils::get_profile_id_from_business_details(
let profile_id = match crate::core::utils::get_profile_id_from_business_details(
business_country_default,
business_label_default.as_ref(),
&merchant_from_db,
Expand All @@ -61,19 +61,25 @@ pub async fn generate_sample_data(
false,
)
.await
.map(|id| id.clone())
.unwrap_or(
state
.store
.list_business_profile_by_merchant_id(&merchant_id)
.await
.change_context(SampleDataError::InternalServerError)
.attach_printable("Failed to get business profile")?
.first()
.ok_or(SampleDataError::InternalServerError)?
.profile_id
.clone(),
);
{
Ok(id) => id.clone(),
Err(_) => {
router_env::logger::error!(
"Profile ID not found in business details. Attempting to fetch from the database."
);

state
.store
.list_business_profile_by_merchant_id(&merchant_id)
.await
.change_context(SampleDataError::InternalServerError)
.attach_printable("Failed to get business profile")?
.first()
.ok_or(SampleDataError::InternalServerError)?
.profile_id
.clone()
}
};

// 10 percent payments should be failed
#[allow(clippy::as_conversions)]
Expand Down

0 comments on commit 1ca7d36

Please sign in to comment.