Repository: juspay/hyperswitch
File: crates/router/src/types/transformers.rs (Rust)

Code before:
            unified_details: details
                .unified_details
                .map(|u| payments::ApiUnifiedErrorDetails {
                    category: u.category,
                    message: u.message,
                    standardised_code: u.standardised_code,
                    description: u.description,
                    user_guidance_message: u.user_guidance_message,
                    recommended_action: u.recommended_action,
                }),
            issuer_details: details
                .issuer_details
                .map(|i| payments::ApiIssuerErrorDetails {
                    code: i.code,
                    message: i.message,
                    network_details: i.network_details.map(|n| payments::ApiNetworkErrorDetails {
                        name: n.name,
                        advice_code: n.advice_code,
                        advice_message: n.advice_message,
                    }),
                }),
            connector_details: details.connector_details.map(|c| {
                payments::ApiConnectorErrorDetails {
                    code: c.code,
                    message: c.message,
                    reason: c.reason,
                }
            }),
        }
    }
}

impl ForeignTryFrom<domain::MerchantConnectorAccount>
    for api_models::admin::MerchantConnectorListResponse
{
    type Error = error_stack::Report<errors::ApiErrorResponse>;
    fn foreign_try_from(item: domain::MerchantConnectorAccount) -> Result<Self, Self::Error> {
        #[cfg(feature = "v1")]
        let payment_methods_enabled = match item.payment_methods_enabled {
            Some(secret_val) => {
                let val = secret_val
                    .into_iter()
                    .map(|secret| secret.expose())
                    .collect();
                serde_json::Value::Array(val)
                    .parse_value("PaymentMethods")
                    .change_context(errors::ApiErrorResponse::InternalServerError)?
            }
            None => None,
        };


Review comment (suggestion):
Please avoid using short variable names like `u`, `c`, and `i`.
Use more descriptive names to improve readability and maintainability of the code.

Code after:
    fn foreign_from(unified: diesel_models::payment_attempt::UnifiedErrorDetails) -> Self {
        Self {
            category: unified.category,
            message: unified.message,
            standardised_code: unified.standardised_code,
            description: unified.description,
            user_guidance_message: unified.user_guidance_message,
            recommended_action: unified.recommended_action,
        }
    }
}

#[cfg(feature = "v1")]
impl ForeignFrom<diesel_models::payment_attempt::NetworkErrorDetails>
    for payments::ApiNetworkErrorDetails
{
    fn foreign_from(network: diesel_models::payment_attempt::NetworkErrorDetails) -> Self {
        Self {
            name: network.name,
            advice_code: network.advice_code,
            advice_message: network.advice_message,
        }
    }
}

#[cfg(feature = "v1")]
impl ForeignFrom<diesel_models::payment_attempt::IssuerErrorDetails>
    for payments::ApiIssuerErrorDetails
{
    fn foreign_from(issuer: diesel_models::payment_attempt::IssuerErrorDetails) -> Self {
        Self {
            code: issuer.code,
            message: issuer.message,
            network_details: issuer
                .network_details
                .map(payments::ApiNetworkErrorDetails::foreign_from),
        }
    }
}

#[cfg(feature = "v1")]
impl ForeignFrom<diesel_models::payment_attempt::ConnectorErrorDetails>
    for payments::ApiConnectorErrorDetails
{
    fn foreign_from(connector: diesel_models::payment_attempt::ConnectorErrorDetails) -> Self {
        Self {
            code: connector.code,
            message: connector.message,
            reason: connector.reason,
        }
    }