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

clean up use of public_error_from_diesel* #644

Merged
merged 3 commits into from
Jan 26, 2022
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
47 changes: 14 additions & 33 deletions common/src/api/external/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ pub enum LookupType {
ByName(String),
/** a specific id was requested */
ById(Uuid),
/** some other lookup type was used */
Other(String),
}

impl LookupType {
Expand Down Expand Up @@ -133,14 +131,6 @@ impl Error {
LookupType::ById(*id).into_not_found(type_name)
}

/**
* Generates an [`Error::ObjectNotFound`] error for some other kind of
* lookup.
*/
pub fn not_found_other(type_name: ResourceType, message: String) -> Error {
LookupType::Other(message).into_not_found(type_name)
}

/**
* Generates an [`Error::InternalError`] error with the specific message
*
Expand Down Expand Up @@ -186,29 +176,20 @@ impl From<Error> for HttpError {
fn from(error: Error) -> HttpError {
match error {
Error::ObjectNotFound { type_name: t, lookup_type: lt } => {
if let LookupType::Other(message) = lt {
HttpError::for_client_error(
Some(String::from("ObjectNotFound")),
http::StatusCode::NOT_FOUND,
message,
)
} else {
/* TODO-cleanup is there a better way to express this? */
let (lookup_field, lookup_value) = match lt {
LookupType::ByName(name) => ("name", name),
LookupType::ById(id) => ("id", id.to_string()),
LookupType::Other(_) => panic!("unhandled other"),
};
let message = format!(
"not found: {} with {} \"{}\"",
t, lookup_field, lookup_value
);
HttpError::for_client_error(
Some(String::from("ObjectNotFound")),
http::StatusCode::NOT_FOUND,
message,
)
}
/* TODO-cleanup is there a better way to express this? */
let (lookup_field, lookup_value) = match lt {
LookupType::ByName(name) => ("name", name),
LookupType::ById(id) => ("id", id.to_string()),
};
let message = format!(
"not found: {} with {} \"{}\"",
t, lookup_field, lookup_value
);
HttpError::for_client_error(
Some(String::from("ObjectNotFound")),
http::StatusCode::NOT_FOUND,
message,
)
}

Error::ObjectAlreadyExists { type_name: t, object_name: n } => {
Expand Down
1 change: 1 addition & 0 deletions nexus/src/authz/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@
mod actor;

mod api_resources;
pub use api_resources::ApiResource;
pub use api_resources::Fleet;
pub use api_resources::FleetChild;
pub use api_resources::Organization;
Expand Down
Loading