diff --git a/src/api/legacy.rs b/src/api/legacy.rs index 552c553..4020601 100644 --- a/src/api/legacy.rs +++ b/src/api/legacy.rs @@ -512,7 +512,15 @@ async fn handle_file_upload( while let Some(Ok(chunk)) = field.next().await { if sender.send(chunk).await.is_err() { - return Err((StatusCode::GONE, "upload cancelled").into()); + return Err(( + StatusCode::INTERNAL_SERVER_ERROR, + ss.status() + .await + .error_message() + .unwrap_or("transfer cancelled") + .to_string(), + ) + .into()); } } diff --git a/src/api/streaming_data_service.rs b/src/api/streaming_data_service.rs index e1a0866..e4357a6 100644 --- a/src/api/streaming_data_service.rs +++ b/src/api/streaming_data_service.rs @@ -227,6 +227,17 @@ pub enum StreamingState { Error(String), } +impl StreamingState { + /// returns the error message when self == `StreamingState::Error(msg)`. + /// Otherwise returns `None`. + pub fn error_message(&self) -> Option<&str> { + if let StreamingState::Error(msg) = self { + return Some(msg); + } + None + } +} + impl Display for StreamingState { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self {