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

Code before:
                                    "message": "Error while rendering payment link status page"
                                }
                            }"#,
                        ),
                    }
                }
            }
        }

        Ok(ApplicationResponse::JsonWithHeaders((response, headers))) => {
            let request_elapsed_time = request.headers().get(X_HS_LATENCY).and_then(|value| {
                if value == "true" {
                    Some(start_instant.elapsed())
                } else {
                    None
                }
            });
            let proxy_connector_http_status_code = if state
                .conf
                .proxy_status_mapping
                .enable_proxy_connector_http_status_code
            {
                headers
                    .iter()
                    .find(|(key, _)| key == "connector_http_status_code")
                    .and_then(|(_, value)| value.clone().into_inner().parse::<u16>().ok())
            } else {
                None
            };
            match serde_json::to_string(&response) {
                Ok(res) => http_response_json_with_headers(
                    res,
                    headers,
                    request_elapsed_time,
                    proxy_connector_http_status_code,
                ),
                Err(_) => http_response_err(
                    r#"{
                        "error": {
                            "message": "Error serializing response from connector"
                        }
                    }"#,
                ),
            }
        }
        Err(error) => log_and_return_error_response(error),
    };

    let response_code = res.status().as_u16();
    tracing::Span::current().record("status_code", response_code);


Review comment (bug):
We are ignoring the parsing error here (when the value is not a valid `u16`). Should we consider logging it here instead?

Code after:
                                    "message": "Error while rendering payment link status page"
                                }
                            }"#,
                        ),
                    }
                }
            }
        }

        Ok(ApplicationResponse::JsonWithHeaders((response, headers))) => {
            let request_elapsed_time = request.headers().get(X_HS_LATENCY).and_then(|value| {
                if value == "true" {
                    Some(start_instant.elapsed())
                } else {
                    None
                }
            });
            let proxy_connector_http_status_code = if state
                .conf
                .proxy_status_mapping
                .proxy_connector_http_status_code
            {
                headers
                    .iter()
                    .find(|(key, _)| key == headers::X_CONNECTOR_HTTP_STATUS_CODE)
                    .and_then(|(_, value)| {
                        match value.clone().into_inner().parse::<u16>() {
                            Ok(code) => match http::StatusCode::from_u16(code) {
                                Ok(status_code) => Some(status_code),
                                Err(err) => {
                                    logger::error!(
                                        "Invalid HTTP status code parsed from connector_http_status_code: {:?}",
                                        err
                                    );
                                    None
                                }
                            },
                            Err(err) => {
                                logger::error!(
                                    "Failed to parse connector_http_status_code from header: {:?}",
                                    err
                                );
                                None
                            }
                        }
                    })
            } else {
                None
            };
            match serde_json::to_string(&response) {
                Ok(res) => http_response_json_with_headers(