Skip to content
This repository was archived by the owner on Jul 6, 2024. It is now read-only.

Commit 5349efb

Browse files
committed
refactor: Include more details in errors
1 parent 5e5f26f commit 5349efb

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "proton-api-rs"
33
authors = ["Leander Beernaert <lbb-dev@pm.me>"]
4-
version = "0.5.0"
4+
version = "0.5.1"
55
edition = "2021"
66
license = "AGPL-3.0-only"
77
description = "Unofficial implemention of proton REST API in rust"

src/client/error.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ pub enum RequestError {
1717
#[derive(Debug, Error)]
1818
/// Errors that may occur during an HTTP request, mostly related to network.
1919
pub enum HttpClientError {
20-
#[error("A redirect error occurred at '{0}")]
21-
Redirect(String),
20+
#[error("A redirect error occurred at '{0}: {1}")]
21+
Redirect(String, #[source] anyhow::Error),
2222
#[error("Connection timed out")]
23-
Timeout,
24-
#[error("Connection error occurred")]
25-
Connection,
26-
#[error("An error occurred related to either the request or response body")]
27-
Body,
28-
#[error("An error occurred preparing the request")]
29-
Request,
23+
Timeout(#[source] anyhow::Error),
24+
#[error("Connection error: {0}")]
25+
Connection(#[source] anyhow::Error),
26+
#[error("Request/Response body error: {0}")]
27+
Body(#[source] anyhow::Error),
28+
#[error("Request error:{0}")]
29+
Request(#[source] anyhow::Error),
3030
#[error("Unexpected error occurred: {0}")]
3131
Other(#[source] anyhow::Error),
3232
}

src/client/http_client/reqwest_client.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,22 +167,23 @@ impl From<reqwest::Error> for HttpClientError {
167167
fn from(value: reqwest::Error) -> Self {
168168
#[cfg(not(target_arch = "wasm32"))]
169169
if value.is_connect() {
170-
return HttpClientError::Connection;
170+
return HttpClientError::Connection(anyhow::Error::new(value));
171171
}
172172

173173
if value.is_body() {
174-
HttpClientError::Body
174+
HttpClientError::Body(anyhow::Error::new(value))
175175
} else if value.is_redirect() {
176176
HttpClientError::Redirect(
177177
value
178178
.url()
179179
.map(|v| v.to_string())
180180
.unwrap_or("Unknown URL".to_string()),
181+
anyhow::Error::new(value),
181182
)
182183
} else if value.is_timeout() {
183-
HttpClientError::Timeout
184+
HttpClientError::Timeout(anyhow::Error::new(value))
184185
} else if value.is_request() {
185-
HttpClientError::Request
186+
HttpClientError::Request(anyhow::Error::new(value))
186187
} else {
187188
HttpClientError::Other(anyhow::Error::new(value))
188189
}

0 commit comments

Comments
 (0)