diff --git a/src/client/error.rs b/src/client/error.rs index 2e2dbcb..74915e0 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("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 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))