Await a Data Plane response, mapping timeout / channel-closed / error-status into `crate::Error::Internal` with a contextual `op_label`.
(
rx: impl std::future::Future<Output = Result<Response, ()>>,
op_label: &str,
)
| 411 | /// Await a Data Plane response, mapping timeout / channel-closed / error-status |
| 412 | /// into `crate::Error::Internal` with a contextual `op_label`. |
| 413 | async fn await_data_plane( |
| 414 | rx: impl std::future::Future<Output = Result<Response, ()>>, |
| 415 | op_label: &str, |
| 416 | ) -> ProposeResult { |
| 417 | match tokio::time::timeout(Duration::from_secs(30), rx).await { |
| 418 | Ok(Ok(resp)) if resp.status == Status::Ok => Ok(resp.payload.to_vec()), |
| 419 | Ok(Ok(resp)) => { |
| 420 | let detail = resp |
| 421 | .error_code |
| 422 | .as_ref() |
| 423 | .map(|c| format!("{op_label} error: {c:?}")) |
| 424 | .unwrap_or_else(|| format!("{op_label} returned error status")); |
| 425 | Err(crate::Error::Internal { detail }) |
| 426 | } |
| 427 | Ok(Err(_)) => Err(crate::Error::Internal { |
| 428 | detail: format!("{op_label}: response channel closed"), |
| 429 | }), |
| 430 | Err(_) => Err(crate::Error::Internal { |
| 431 | detail: format!("{op_label}: deadline exceeded"), |
| 432 | }), |
| 433 | } |
| 434 | } |
no test coverage detected