From bebde5f89fa7a81c2930dcb6c5efc4497b1cbfb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20M=C3=BCller?= Date: Sun, 30 Apr 2023 10:31:37 -0700 Subject: [PATCH] Start error rework? --- src/api_info.rs | 13 ++++++++++--- src/error.rs | 8 -------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/api_info.rs b/src/api_info.rs index e6d7437a..04daa64a 100644 --- a/src/api_info.rs +++ b/src/api_info.rs @@ -65,7 +65,10 @@ impl ApiInfo { key_id: impl ToString, secret: impl ToString, ) -> Result { - let api_base_url = Url::parse(api_base_url.as_ref())?; + let api_base_url = api_base_url.as_ref(); + let api_base_url = Url::parse(api_base_url).map_err(|err| { + Error::Str(format!("API base URL {api_base_url} is not valid: {err}").into()) + })?; let api_stream_url = make_api_stream_url(api_base_url.clone())?; Ok(Self { @@ -106,7 +109,9 @@ impl ApiInfo { .map_err(|_| { Error::Str(format!("{ENV_API_BASE_URL} environment variable is not a valid string").into()) })?; - let api_base_url = Url::parse(&api_base_url)?; + let api_base_url = Url::parse(&api_base_url).map_err(|err| { + Error::Str(format!("API base URL {api_base_url} is not valid: {err}").into()) + })?; let api_stream_url = var_os(ENV_API_STREAM_URL) .map(Result::<_, Error>::Ok) @@ -122,7 +127,9 @@ impl ApiInfo { format!("{ENV_API_STREAM_URL} environment variable is not a valid string").into(), ) })?; - let api_stream_url = Url::parse(&api_stream_url)?; + let api_stream_url = Url::parse(&api_stream_url).map_err(|err| { + Error::Str(format!("API stream URL {api_stream_url} is not valid: {err}").into()) + })?; let key_id = var_os(ENV_KEY_ID) .ok_or_else(|| Error::Str(format!("{ENV_KEY_ID} environment variable not found").into()))? diff --git a/src/error.rs b/src/error.rs index a7d1a216..617dfe4f 100644 --- a/src/error.rs +++ b/src/error.rs @@ -13,7 +13,6 @@ use http::StatusCode as HttpStatusCode; use hyper::Error as HyperError; use serde_json::Error as JsonError; use thiserror::Error; -use url::ParseError; use websocket_util::tungstenite::Error as WebSocketError; use crate::Str; @@ -80,13 +79,6 @@ pub enum Error { /// An error directly originating in this crate. #[error("{0}")] Str(Str), - /// An URL parsing error. - #[error("failed to parse the URL")] - Url( - #[from] - #[source] - ParseError, - ), /// A websocket error. #[error("encountered a websocket related error")] WebSocket(