(
sender_client: Arc<backend::Client>,
bp: backend::BasePayload,
b: &[u8],
)
| 439 | } |
| 440 | |
| 441 | async fn handle_xmit_data_req( |
| 442 | sender_client: Arc<backend::Client>, |
| 443 | bp: backend::BasePayload, |
| 444 | b: &[u8], |
| 445 | ) -> Response { |
| 446 | let pl: backend::XmitDataReqPayload = match serde_json::from_slice(b) { |
| 447 | Ok(v) => v, |
| 448 | Err(e) => { |
| 449 | let ans = err_to_response(anyhow::Error::new(e), &bp); |
| 450 | log_request_response(&bp, b, &ans).await; |
| 451 | return Json(&ans).into_response(); |
| 452 | } |
| 453 | }; |
| 454 | |
| 455 | if sender_client.is_async() { |
| 456 | let b = b.to_vec(); |
| 457 | task::spawn(async move { |
| 458 | let sender_role = if pl.ul_meta_data.is_some() { |
| 459 | backend::Role::FNS |
| 460 | } else { |
| 461 | backend::Role::SNS |
| 462 | }; |
| 463 | |
| 464 | let ans = match _handle_xmit_data_req(pl).await { |
| 465 | Ok(v) => v, |
| 466 | Err(e) => { |
| 467 | let msg = e.to_string(); |
| 468 | backend::XmitDataAnsPayload { |
| 469 | base: bp.to_base_payload_result(err_to_result_code(e), &msg), |
| 470 | } |
| 471 | } |
| 472 | }; |
| 473 | |
| 474 | log_request_response(&bp, &b, &ans).await; |
| 475 | |
| 476 | if let Err(e) = sender_client.xmit_data_ans(sender_role, &ans).await { |
| 477 | error!(error = %e.full(), "Send async XmitDataAns error"); |
| 478 | } |
| 479 | }); |
| 480 | (StatusCode::OK, "").into_response() |
| 481 | } else { |
| 482 | match _handle_xmit_data_req(pl).await { |
| 483 | Ok(ans) => { |
| 484 | log_request_response(&bp, b, &ans).await; |
| 485 | Json(&ans).into_response() |
| 486 | } |
| 487 | Err(e) => { |
| 488 | let ans = err_to_response(e, &bp); |
| 489 | log_request_response(&bp, b, &ans).await; |
| 490 | Json(&ans).into_response() |
| 491 | } |
| 492 | } |
| 493 | } |
| 494 | } |
| 495 | |
| 496 | async fn _handle_xmit_data_req( |
| 497 | pl: backend::XmitDataReqPayload, |
no test coverage detected