Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Clean up apierrors and only include messages #1329

Merged
merged 2 commits into from
May 27, 2020
Merged
Changes from 1 commit
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
7 changes: 6 additions & 1 deletion src/commands/kv/namespace/site.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ pub fn site(

get_id_from_namespace_list(&client, target, &title)
} else {
failure::bail!("{:?}", api_errors.errors)
let error_messages: Vec<String> = api_errors
.errors
.iter()
.map(|e| e.message.clone())
.collect();
failure::bail!("ApiError {:?}", error_messages);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh actually - it looks like we already have a convenience function for this that should make it easier + uniform with the way we display errors.

It is crate::http::format_error, and it takes an ApiFailure, and an optional function to handle individual error codes.

So you could write something real quick to include the suggestions for codes 10026 and 10014 and pass it to that function. You can see an example of this in crate::src::commands::route::delete, at the end there is a match result and it calls http::format_error

This should allow us to display the error without making it look like an array

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(if i had thought of this before i would have pointed you in that direction!)

}
}
ApiFailure::Invalid(reqwest_err) => failure::bail!("Error: {}", reqwest_err),
Expand Down