Repository: juspay/hyperswitch
File: crates/router/src/core/routing.rs (Rust)

Code before:
pub async fn decide_gateway_open_router(
    state: SessionState,
    // merchant_context: domain::MerchantContext,
    req_body: OpenRouterDecideGatewayRequest,
) -> RouterResponse<DecideGatewayResponse> {
    let response = SRApiClient::send_decision_engine_request(
        &state,
        Method::Post,
        "decide-gateway",
        Some(req_body),
        None,
        None,
    )
    .await
    .change_context(errors::ApiErrorResponse::InternalServerError)
    .attach_printable("Failed to perform decide gateway call with open router")?;

    let response_value: serde_json::Value = response
        .response
        .get_required_value("response")
        .change_context(errors::ApiErrorResponse::InternalServerError)
        .attach_printable("Response from decision engine not obtained")?;
    let res: DecideGatewayResponse = response_value
        .parse_value("DecideGatewayResponse")
        .change_context(errors::ApiErrorResponse::InternalServerError)
        .attach_printable("Failed to parse DecidedGateway from response")?;

    Ok(hyperswitch_domain_models::api::ApplicationResponse::Json(
        res,
    ))
}

pub async fn update_gateway_score_open_router(
    state: SessionState,
    req_body: UpdateScorePayload,
) -> RouterResponse<UpdateScoreResponse> {
    let response = SRApiClient::send_decision_engine_request(
        &state,
        Method::Post,
        "update-gateway-score",
        Some(req_body),
        None,
        None,
    )
    .await
    .change_context(errors::ApiErrorResponse::InternalServerError)
    .attach_printable("Failed to perform update gateway score call with open router")?;

    let response_value: serde_json::Value = response
        .response
        .get_required_value("response")

Review comment (bug):
```suggestion
    let response :  DecideGatewayResponse  = SRApiClient::send_decision_engine_request(
        &state,
        Method::Post,
        "decide-gateway",
        Some(req_body),
        None,
        None,
    )
    .await?
    .response
    .change_context(errors::ApiErrorResponse::InternalServerError)
    .attach_printable("Failed to perform decide gateway call with open router")?;
```

check if this is possible

Code after:
pub async fn decide_gateway_open_router(
    state: SessionState,
    req_body: OpenRouterDecideGatewayRequest,
) -> RouterResponse<DecideGatewayResponse> {
    let response = if state.conf.open_router.dynamic_routing_enabled {
        SRApiClient::send_decision_engine_request(
            &state,
            Method::Post,
            "decide-gateway",
            Some(req_body),
            None,
            None,
        )
        .await
        .change_context(errors::ApiErrorResponse::InternalServerError)?
        .response
        .ok_or(errors::ApiErrorResponse::InternalServerError)
        .attach_printable("Failed to perform decide gateway call with open router")?
    } else {
        Err(errors::ApiErrorResponse::InternalServerError)
            .attach_printable("Dynamic routing is not enabled")?
    };

    Ok(hyperswitch_domain_models::api::ApplicationResponse::Json(
        response,
    ))
}

pub async fn update_gateway_score_open_router(
    state: SessionState,
    req_body: UpdateScorePayload,
) -> RouterResponse<UpdateScoreResponse> {
    let response = if state.conf.open_router.dynamic_routing_enabled {
        SRApiClient::send_decision_engine_request(
            &state,
            Method::Post,
            "update-gateway-score",
            Some(req_body),
            None,
            None,
        )
        .await
        .change_context(errors::ApiErrorResponse::InternalServerError)?
        .response
        .ok_or(errors::ApiErrorResponse::InternalServerError)
        .attach_printable("Failed to perform update gateway score call with open router")?
    } else {
        Err(errors::ApiErrorResponse::InternalServerError)
            .attach_printable("Dynamic routing is not enabled")?
    };