From b44f9a7ea6a3bb8ebd837666ba7231bd5bb0e57d Mon Sep 17 00:00:00 2001 From: Matt Butcher Date: Fri, 10 Sep 2021 12:24:37 -0600 Subject: [PATCH 1/2] improve error messages for network connection failures Signed-off-by: Matt Butcher --- src/client/error.rs | 4 ++-- src/client/mod.rs | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/client/error.rs b/src/client/error.rs index 2e2dbcb..5ff1647 100644 --- a/src/client/error.rs +++ b/src/client/error.rs @@ -52,13 +52,13 @@ pub enum ClientError { ParcelAlreadyExists, /// The error returned when the request is invalid. Contains the underlying HTTP status code and /// any message returned from the API - #[error("Invalid request (status code {status_code:?}): {message:?}")] + #[error("Invalid request (status code {status_code:?}): {}", .message.clone().unwrap_or_else(|| "unknown error".to_owned()))] InvalidRequest { status_code: reqwest::StatusCode, message: Option, }, /// A server error was encountered. Contains an optional message from the server - #[error("Server has encountered an error: {0:?}")] + #[error("Server has encountered an error: {}", .0.clone().unwrap_or_else(||"Protocol error. Verify the Bindle URL".to_owned()))] ServerError(Option), /// Invalid credentials were used or user does not have access to the requested resource. This /// is only valid if the server supports authentication and/or permissions diff --git a/src/client/mod.rs b/src/client/mod.rs index 39949b3..ffa4b64 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -617,6 +617,10 @@ async fn unwrap_status( (StatusCode::CONFLICT, Endpoint::Invoice) => Err(ClientError::InvoiceAlreadyExists), (StatusCode::CONFLICT, Endpoint::Parcel) => Err(ClientError::ParcelAlreadyExists), (StatusCode::UNAUTHORIZED, _) => Err(ClientError::Unauthorized), + (StatusCode::BAD_REQUEST, _) => Err(ClientError::ServerError(Some( + "The request could not be handled by the server. Verify your Bindle server URL" + .to_owned(), + ))), // You can't range match on u16 so we use a guard (_, _) if resp.status().is_server_error() => { Err(ClientError::ServerError(parse_error_from_body(resp).await)) From e7da8e6310c7843ff8d4427e8a422d2c82132d83 Mon Sep 17 00:00:00 2001 From: Matt Butcher Date: Wed, 15 Sep 2021 14:26:23 -0600 Subject: [PATCH 2/2] Error contacting server Signed-off-by: Matt Butcher --- src/client/error.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/error.rs b/src/client/error.rs index 5ff1647..74915e0 100644 --- a/src/client/error.rs +++ b/src/client/error.rs @@ -58,7 +58,7 @@ pub enum ClientError { message: Option, }, /// A server error was encountered. Contains an optional message from the server - #[error("Server has encountered an error: {}", .0.clone().unwrap_or_else(||"Protocol error. Verify the Bindle URL".to_owned()))] + #[error("Error contacting server: {}", .0.clone().unwrap_or_else(||"Protocol error. Verify the Bindle URL".to_owned()))] ServerError(Option), /// Invalid credentials were used or user does not have access to the requested resource. This /// is only valid if the server supports authentication and/or permissions