Repository: juspay/hyperswitch
File: crates/router/src/services/api.rs (Rust)

Code before:
    let css_template =
        include_str!("../core/payment_link/payment_link_initiate/payment_link.css").to_string();
    let _ = tera.add_raw_template("payment_link_css", &css_template);
    let mut context = Context::new();
    context.insert("css_color_scheme", &payment_link_data.css_script);

    let rendered_css = match tera.render("payment_link_css", &context) {
        Ok(rendered_css) => rendered_css,
        Err(tera_error) => {
            crate::logger::warn!("{tera_error}");
            Err(errors::ApiErrorResponse::InternalServerError)?
        }
    };

    // Add modification to js template with dynamic data
    let js_template =
        include_str!("../core/payment_link/payment_link_initiate/payment_link.js").to_string();

    let _ = tera.add_raw_template("payment_link_js", &js_template);

    context.insert("payment_details_js_script", &payment_link_data.js_script);
    let sdk_origin = payment_link_data
        .sdk_url
        .host_str()
        .ok_or_else(|| {
            crate::logger::error!("Host missing for payment link SDK URL");
            report!(errors::ApiErrorResponse::InternalServerError)
        })
        .and_then(|host| {
            if host == "localhost" {
                let port = payment_link_data.sdk_url.port().ok_or_else(|| {
                    crate::logger::error!("Port missing for localhost in SDK URL");
                    report!(errors::ApiErrorResponse::InternalServerError)
                })?;
                Ok(format!(
                    "{}://{}:{}",
                    payment_link_data.sdk_url.scheme(),
                    host,
                    port
                ))
            } else {
                Ok(format!("{}://{}", payment_link_data.sdk_url.scheme(), host))
            }
        })?;
    context.insert("sdk_origin", &sdk_origin);

    let rendered_js = match tera.render("payment_link_js", &context) {
        Ok(rendered_js) => rendered_js,
        Err(tera_error) => {
            crate::logger::warn!("{tera_error}");
            Err(errors::ApiErrorResponse::InternalServerError)?

Review comment (suggestion):
```suggestion
            logger::error!("Host missing for payment link SDK URL");
```

Code after:

    let rendered_css = match tera.render("payment_link_css", &context) {
        Ok(rendered_css) => rendered_css,
        Err(tera_error) => {
            crate::logger::warn!("{tera_error}");
            Err(errors::ApiErrorResponse::InternalServerError)?
        }
    };

    //Locale template
    let locale_template = include_str!("../core/payment_link/locale.js");

    // Logging template
    let logging_template =
        include_str!("redirection/assets/redirect_error_logs_push.js").to_string();

    // Add modification to js template with dynamic data
    let js_template =
        include_str!("../core/payment_link/payment_link_status/status.js").to_string();
    let _ = tera.add_raw_template("payment_link_js", &js_template);
    context.insert("payment_details_js_script", &payment_link_data.js_script);

    let rendered_js = match tera.render("payment_link_js", &context) {
        Ok(rendered_js) => rendered_js,
        Err(tera_error) => {
            crate::logger::warn!("{tera_error}");
            Err(errors::ApiErrorResponse::InternalServerError)?
        }
    };

    // Modify Html template with rendered js and rendered css files
    let html_template =
        include_str!("../core/payment_link/payment_link_status/status.html").to_string();
    let _ = tera.add_raw_template("payment_link_status", &html_template);

    context.insert("rendered_css", &rendered_css);
    context.insert("locale_template", &locale_template);

    context.insert("rendered_js", &rendered_js);
    context.insert("logging_template", &logging_template);

    match tera.render("payment_link_status", &context) {
        Ok(rendered_html) => Ok(rendered_html),
        Err(tera_error) => {
            crate::logger::warn!("{tera_error}");
            Err(errors::ApiErrorResponse::InternalServerError)?
        }
    }
}

#[cfg(test)]