Repository: juspay/hyperswitch
File: crates/hyperswitch_domain_models/src/business_profile.rs (Rust)

Code before:
            merchant_country_code: value.merchant_country_code,
        }
    }
}

impl Profile {
    #[cfg(feature = "v1")]
    pub fn get_id(&self) -> &common_utils::id_type::ProfileId {
        &self.profile_id
    }

    pub fn get_country_from_merchant_country_code(
        &self,
    ) -> CustomResult<Option<common_enums::Country>, api_error_response::ApiErrorResponse> {
        self.merchant_country_code
            .as_ref()
            .map(|country_code| match country_code.parse::<u32>() {
                Ok(code) => match common_enums::Country::from_numeric(code) {
                    Ok(country) => Ok(country),
                    Err(err) => {
                        router_env::logger::error!("Invalid country code {}: {:?}", code, err);
                        Err(error_stack::Report::new(
                            api_error_response::ApiErrorResponse::InvalidDataValue {
                                field_name: "merchant_country_code",
                            },
                        ))
                    }
                },
                Err(err) => {
                    router_env::logger::error!(
                        "Country code {} is negative or too large: {:?}",
                        country_code,
                        err
                    );
                    Err(error_stack::Report::new(
                        api_error_response::ApiErrorResponse::InvalidDataValue {
                            field_name: "merchant_country_code",
                        },
                    ))
                }
            })
            .transpose()
    }
    #[cfg(feature = "v2")]
    pub fn get_id(&self) -> &common_utils::id_type::ProfileId {
        &self.id
    }
}

#[cfg(feature = "v1")]
#[derive(Debug)]

Review comment (bug):
Instead of logging an error and then returning a Report, can we do `attach_printable` on Report itself. because this will produce 2 different logs (one from logger:error and other from propagated parent error log) and makes debugging little difficult

Code after:
            merchant_country_code: value.merchant_country_code,
        }
    }
}

impl Profile {
    #[cfg(feature = "v1")]
    pub fn get_id(&self) -> &common_utils::id_type::ProfileId {
        &self.profile_id
    }

    #[cfg(feature = "v2")]
    pub fn get_id(&self) -> &common_utils::id_type::ProfileId {
        &self.id
    }
}

#[cfg(feature = "v1")]
#[derive(Debug)]
pub struct ProfileGeneralUpdate {
    pub profile_name: Option<String>,
    pub return_url: Option<String>,
    pub enable_payment_response_hash: Option<bool>,
    pub payment_response_hash_key: Option<String>,
    pub redirect_to_merchant_with_http_post: Option<bool>,
    pub webhook_details: Option<WebhookDetails>,
    pub metadata: Option<pii::SecretSerdeValue>,
    pub routing_algorithm: Option<serde_json::Value>,
    pub intent_fulfillment_time: Option<i64>,
    pub frm_routing_algorithm: Option<serde_json::Value>,
    pub payout_routing_algorithm: Option<serde_json::Value>,
    pub applepay_verified_domains: Option<Vec<String>>,
    pub payment_link_config: Option<BusinessPaymentLinkConfig>,
    pub session_expiry: Option<i64>,
    pub authentication_connector_details: Option<AuthenticationConnectorDetails>,
    pub payout_link_config: Option<BusinessPayoutLinkConfig>,
    pub extended_card_info_config: Option<pii::SecretSerdeValue>,
    pub use_billing_as_payment_method_billing: Option<bool>,
    pub collect_shipping_details_from_wallet_connector: Option<bool>,
    pub collect_billing_details_from_wallet_connector: Option<bool>,
    pub is_connector_agnostic_mit_enabled: Option<bool>,
    pub outgoing_webhook_custom_http_headers: OptionalEncryptableValue,
    pub always_collect_billing_details_from_wallet_connector: Option<bool>,
    pub always_collect_shipping_details_from_wallet_connector: Option<bool>,
    pub tax_connector_id: Option<common_utils::id_type::MerchantConnectorAccountId>,
    pub is_tax_connector_enabled: Option<bool>,
    pub dynamic_routing_algorithm: Option<serde_json::Value>,
    pub is_network_tokenization_enabled: Option<bool>,
    pub is_auto_retries_enabled: Option<bool>,
    pub max_auto_retries_enabled: Option<i16>,
    pub is_click_to_pay_enabled: Option<bool>,