Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

streaming_data_service: improve error message #70

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/api/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand Down
11 changes: 11 additions & 0 deletions src/api/streaming_data_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading