diff --git a/agent/src/error.rs b/agent/src/error.rs index 1c2832cf..25ecb63a 100644 --- a/agent/src/error.rs +++ b/agent/src/error.rs @@ -5,8 +5,8 @@ pub enum Error { AuthorizationFailed, UnableToParseResponse, UrlDoesNotExist, - InternalServerError, UnknownResponseStatusCode(String), + InternalServerError(u16), UnreachableUrl, HttpServiceUnavailable, } @@ -21,8 +21,8 @@ impl Display for Error { Error::AuthorizationFailed => write!(f, "Failed to authorize. Either the wrong or no api-key is provided."), Error::UnableToParseResponse => write!(f, "Unable to parse the response from the server. Is the cloudagent the correct version?"), Error::UrlDoesNotExist => write!(f, "Path does not exist on endpoint. This can happen when querying by id and the id is not valid."), - Error::InternalServerError => write!(f, "Internal Server Error!"), Error::UnknownResponseStatusCode(msg) => write!(f, "Received unknown status code from the server. Endpoint is likely incorrect. If the endpoint is correct, please report this error at https://github.com/animo/aries-cli/issues/new \nAdditional info: {}", msg), + Error::InternalServerError(status) => write!(f, "Internal Server Error (status code: {})!", status), Error::UnreachableUrl => write!(f, "Provided url is unreachable. Is the provided endpoint valid?"), Error::HttpServiceUnavailable => write!(f, "Cloudagent is currently unavailable. Are you sure the agent is online?") diff --git a/cli/src/error.rs b/cli/src/error.rs index 34d79a51..bb123bdb 100644 --- a/cli/src/error.rs +++ b/cli/src/error.rs @@ -2,6 +2,7 @@ use std::fmt::{Display, Formatter}; #[derive(Debug)] pub enum Error { + CannotReadConfigurationFile, InvalidConfigurationPath, InvalidConfigurationStructure, InvalidEnvironment, @@ -21,6 +22,7 @@ pub type Result = std::result::Result>; impl Display for Error { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { match self { + Error::CannotReadConfigurationFile => write!(f, "Cannot not read configuration file. Try initializing first using: `aries-cli configuration initialize`."), Error::InvalidConfigurationPath => write!(f, "Invalid configuration path."), Error::InvalidEnvironment => write!(f, "Invalid environment."), Error::NoEndpointSupplied => write!(f, "No endpoint supplied. Supply an endpoint either via `--endpoint` or via `--config`."), diff --git a/cli/src/modules/configuration.rs b/cli/src/modules/configuration.rs index 2a54e666..da6df423 100644 --- a/cli/src/modules/configuration.rs +++ b/cli/src/modules/configuration.rs @@ -2,7 +2,8 @@ use crate::error; use crate::error::Result; use crate::utils::config::{get_config_path, Configurations}; use clap::{Args, Subcommand}; -use log::info; +use colored::*; +use log::{debug, info}; use std::fs; use std::path::Path; @@ -23,10 +24,24 @@ pub async fn parse_configuration_args(options: &ConfigurationOptions) -> Result< match options.commands { ConfigurationSubcommands::Initialize => { initialize(&config_path)?; - info!("Initialized the configuration!"); + info!( + "{} configuration file at {}.", + "Initialised".cyan(), + config_path.display() + ); Ok(()) } - ConfigurationSubcommands::View => view(&config_path), + ConfigurationSubcommands::View => { + debug!( + "Loaded configuration from {}", + String::from(config_path.to_str().unwrap()).bold() + ); + + view(&config_path).map_err(|err| { + debug!("Failed to read config file: {}", err); + error::Error::CannotReadConfigurationFile.into() + }) + } } } diff --git a/cli/src/modules/connections.rs b/cli/src/modules/connections.rs index f766df98..97153963 100644 --- a/cli/src/modules/connections.rs +++ b/cli/src/modules/connections.rs @@ -68,13 +68,19 @@ pub async fn parse_connection_args( }; agent.create_invitation(options).await.map(|response| { loader.stop(); + info!( + "{}", + format!( + "{} invite with connection id: {}\n", + "Created".green(), + response.connection_id, + ) + ); if *qr { - info!( - "{}", - format!("{}: {}", "Connection id".green(), response.connection_id) - ); + info!("Scan this QR code to accept the invitation:\n"); print_qr_code(response.invitation_url).unwrap(); } else { + info!("Another agent can use this URL to accept your invitation:\n"); info!("{}", response.invitation_url) } }) diff --git a/cli/src/modules/credential_definition.rs b/cli/src/modules/credential_definition.rs index 320c60f0..7f345fb0 100644 --- a/cli/src/modules/credential_definition.rs +++ b/cli/src/modules/credential_definition.rs @@ -1,5 +1,6 @@ use agent::modules::credential_definition::CredentialDefinitionModule; use clap::{Args, Subcommand}; +use colored::*; use log::{debug, info}; use serde_json::json; @@ -54,7 +55,11 @@ pub async fn parse_credential_definition_args( agent.create(schema_id.to_string()).await.map(|cred_def| { loader.stop(); copy!("{}", cred_def.credential_definition_id); - info!("{}", cred_def.credential_definition_id); + info!( + "{} credential definition with id: {}.", + "Created".green(), + cred_def.credential_definition_id + ) }) } }, diff --git a/cloudagent-python/src/web.rs b/cloudagent-python/src/web.rs index 4771dced..eba49571 100644 --- a/cloudagent-python/src/web.rs +++ b/cloudagent-python/src/web.rs @@ -64,7 +64,7 @@ impl CloudAgent { // TODO: This response is quite ugly. Is it only used at cred_def_id? 422 => Err(res.text().await?.into()), 503 => Err(Error::HttpServiceUnavailable.into()), - 500..=599 => Err(Error::InternalServerError.into()), + 500..=599 => Err(Error::InternalServerError(res.status().as_u16()).into()), _ => Err(Error::UnknownResponseStatusCode(res.text().await?).into()), } }