|
1 | 1 | use crate::common_args; |
2 | 2 | use crate::config::Config; |
3 | | -use crate::util::{add_auth_header_opt, get_auth_header}; |
| 3 | +use crate::util::{add_auth_header_opt, get_auth_header, ResponseExt}; |
4 | 4 | use clap::ArgMatches; |
5 | 5 | use clap::{Arg, Command}; |
6 | 6 |
|
7 | | -use spacetimedb_client_api_messages::name::DomainName; |
| 7 | +use spacetimedb_client_api_messages::name::{DomainName, SetDomainsResult}; |
8 | 8 |
|
9 | 9 | pub fn cli() -> Command { |
10 | 10 | Command::new("rename") |
@@ -44,10 +44,22 @@ pub async fn exec(mut config: Config, args: &ArgMatches) -> Result<(), anyhow::E |
44 | 44 | let builder = add_auth_header_opt(builder, &auth_header); |
45 | 45 |
|
46 | 46 | let response = builder.send().await?; |
47 | | - let status = response.status(); |
48 | | - let response_body = response.text().await?; |
| 47 | + let status = &response.status(); |
| 48 | + let result : SetDomainsResult = response.json_or_error().await?; |
| 49 | + |
49 | 50 | if !status.is_success() { |
50 | | - anyhow::bail!("Error: {response_body}"); |
| 51 | + anyhow::bail!(match result { |
| 52 | + SetDomainsResult::Success => "".to_string(), |
| 53 | + SetDomainsResult::PermissionDenied { domain } => |
| 54 | + format!("Permission denied for domain: {}", domain), |
| 55 | + SetDomainsResult::PermissionDeniedOnAny { domains } => |
| 56 | + format!("Permission denied for domains: {:?}", domains), |
| 57 | + SetDomainsResult::DatabaseNotFound => |
| 58 | + format!("Database {} not found", database_identity), |
| 59 | + SetDomainsResult::NotYourDatabase { .. } => |
| 60 | + format!("You cannot rename {} because it is owned by another identity.", database_identity), |
| 61 | + SetDomainsResult::OtherError(err) => err, |
| 62 | + }); |
51 | 63 | } |
52 | 64 |
|
53 | 65 | println!("Name set to {} for identity {}.", domain, database_identity); |
|
0 commit comments