Skip to content

Commit

Permalink
Start error rework?
Browse files Browse the repository at this point in the history
  • Loading branch information
d-e-s-o committed Apr 30, 2023
1 parent db5bad6 commit bebde5f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
13 changes: 10 additions & 3 deletions src/api_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ impl ApiInfo {
key_id: impl ToString,
secret: impl ToString,
) -> Result<Self, Error> {
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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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()))?
Expand Down
8 changes: 0 additions & 8 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit bebde5f

Please sign in to comment.