From 3f398c220fd839b41a130b98044e05f4fb09f394 Mon Sep 17 00:00:00 2001 From: Berend Sliedrecht <61358536+blu3beri@users.noreply.github.com> Date: Wed, 9 Mar 2022 15:18:28 +0100 Subject: [PATCH] fix: log the 503 message (#90) Signed-off-by: Berend Sliedrecht --- agent-controller/src/error.rs | 3 +++ agent-controller/src/web.rs | 20 +++++++++++--------- cli/src/error.rs | 1 - 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/agent-controller/src/error.rs b/agent-controller/src/error.rs index cf724150..e00970dd 100644 --- a/agent-controller/src/error.rs +++ b/agent-controller/src/error.rs @@ -8,6 +8,7 @@ pub enum Error { InternalServerError, UnknownResponseStatusCode, UnreachableUrl, + HttpServiceUnavailable, } impl std::error::Error for Error {} @@ -23,6 +24,8 @@ impl Display for Error { Error::InternalServerError => write!(f, "Internal Server Error!"), Error::UnknownResponseStatusCode => write!(f, "Received unknown status code from the server. Endpoint is likely incorrect. If the endpoint is correct, please report this error."), 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/agent-controller/src/web.rs b/agent-controller/src/web.rs index d8331258..ea34b667 100644 --- a/agent-controller/src/web.rs +++ b/agent-controller/src/web.rs @@ -1,4 +1,4 @@ -use crate::error::{self, Result}; +use crate::error::{Error, Result}; use reqwest::{Client, RequestBuilder, Url}; use serde::de::DeserializeOwned; use serde_json::Value; @@ -47,19 +47,21 @@ impl CloudAgent { match client.send().await { Ok(res) => match res.status().as_u16() { - 200..=299 => res.json().await.map_err(|_| - error::Error::UnableToParseResponse.into() - ), + 200..=299 => res + .json() + .await + .map_err(|_| Error::UnableToParseResponse.into()), // Issue credential message when attributes are not correct 400 => Err(res.text().await?.into()), - 401 => Err(error::Error::AuthorizationFailed.into()), - 404 => Err(error::Error::UrlDoesNotExist.into()), + 401 => Err(Error::AuthorizationFailed.into()), + 404 => Err(Error::UrlDoesNotExist.into()), // TODO: This response is quite ugly. Is it only used at cred_def_id? 422 => Err(res.text().await?.into()), - 500..=599 => Err(error::Error::InternalServerError.into()), - _ => Err(error::Error::UnknownResponseStatusCode.into()), + 503 => Err(Error::HttpServiceUnavailable.into()), + 500..=599 => Err(Error::InternalServerError.into()), + _ => Err(Error::UnknownResponseStatusCode.into()), }, - Err(_) => Err(error::Error::UnreachableUrl.into()), + Err(_) => Err(Error::UnreachableUrl.into()), } } } diff --git a/cli/src/error.rs b/cli/src/error.rs index 7597ebab..ba8fd74c 100644 --- a/cli/src/error.rs +++ b/cli/src/error.rs @@ -33,7 +33,6 @@ impl Display for Error { Error::NoFlagSupplied(subcommand) => write!(f, "The subcommand {} requires atleast one flag. Check `aries-cli {} --help for the available options.", subcommand, subcommand), Error::RequiredAttributes => write!(f, "Creating a schema requires at least one attribute. Please supply them via the --attributes flag."), Error::InvalidConfigurationStructure => write!(f, "Invalid configuration structure. Please make sure you have a valid configuration file."), - } } }