Skip to content

Commit

Permalink
Return 400 Bad Request for responses that contain empty graph
Browse files Browse the repository at this point in the history
Return `400 Bad Request` for responses that contain an empty graph. Such
responses are currently only generated when a specified channel and
architecture result in an empty update graph due to the filtering.

This commit is part of the effort to improve the UX regarding requests
that contain invalid query parameters. In the future, more fine-grained
return messages will be returned.
  • Loading branch information
DavidHurta committed Aug 30, 2024
1 parent 5092fee commit 7576bce
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions commons/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ pub enum GraphError {
/// Resource does not exist
#[error("does not exist: {}", _0)]
DoesNotExist(String),

/// No version were found.
#[error("no versions found: {}", _0)]
NoVersionsFound(String),
}

impl actix_web::error::ResponseError for GraphError {
Expand Down Expand Up @@ -129,6 +133,7 @@ impl GraphError {
GraphError::ArchVersionError(_) => http::StatusCode::INTERNAL_SERVER_ERROR,
GraphError::FileOpenError(_) => http::StatusCode::INTERNAL_SERVER_ERROR,
GraphError::DoesNotExist(_) => http::StatusCode::NOT_FOUND,
GraphError::NoVersionsFound(_) => http::StatusCode::BAD_REQUEST,
}
}

Expand All @@ -146,6 +151,7 @@ impl GraphError {
GraphError::ArchVersionError(_) => "arch_version_error",
GraphError::FileOpenError(_) => "file_open_err",
GraphError::DoesNotExist(_) => "does_not_exist",
GraphError::NoVersionsFound(_) => "no_versions_found",
};
kind.to_string()
}
Expand Down
4 changes: 4 additions & 0 deletions policy-engine/src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ where
Err(other_error) => GraphError::FailedPluginExecution(other_error.to_string()),
})?;

if internal_io.graph.releases_count() == 0 {
return Err(GraphError::NoVersionsFound("the specified architecture and/or channel does not contain any versions".to_string()));
}

let versioned_graph = add_version_information(&internal_io);

let graph_json = serde_json::to_string(&versioned_graph)
Expand Down

0 comments on commit 7576bce

Please sign in to comment.