Skip to content

Commit

Permalink
Merge pull request #4 from unbekanntes-pferd/feature/client-config
Browse files Browse the repository at this point in the history
feature/client config
  • Loading branch information
unbekanntes-pferd committed Jul 9, 2023
2 parents f7ec48a + 4a8f859 commit dfc0ee9
Show file tree
Hide file tree
Showing 9 changed files with 268 additions and 71 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ description = "Async API wrapper for DRACOON in Rust."
[dependencies]
# HTTP client
reqwest = {version = "0.11.14", features = ["json", "stream"]}
reqwest-middleware = "0.2.2"
reqwest-retry = "0.2.2"

# crypto
dco3_crypto = "0.5.0"
Expand All @@ -35,6 +37,7 @@ serde_json = "1.0.95"

# error handling
thiserror = "1.0.2"
retry-policies = "0.1.0"

# logging and tracing
tracing = "0.1.37"
Expand Down
40 changes: 37 additions & 3 deletions src/auth/errors.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use async_trait::async_trait;
use dco3_crypto::DracoonCryptoError;
use reqwest::{Error as ReqError, Response};
use reqwest_middleware::{Error as ReqError};
use reqwest::{Error as ClientError, Response};
use thiserror::Error;

use crate::{nodes::models::S3ErrorResponse, utils::FromResponse};
Expand Down Expand Up @@ -43,14 +44,47 @@ pub enum DracoonClientError {

impl From<ReqError> for DracoonClientError {
fn from(value: ReqError) -> Self {
if value.is_builder() {
return DracoonClientError::Internal;

match value {
ReqError::Middleware(error) => {
DracoonClientError::ConnectionFailed

},
ReqError::Reqwest(error) => {
if error.is_timeout() {
return DracoonClientError::ConnectionFailed
}

if error.is_connect() {
return DracoonClientError::ConnectionFailed
}


DracoonClientError::Unknown

},
}
}
}


impl From<ClientError> for DracoonClientError {
fn from(value: ClientError) -> Self {

if value.is_timeout() {
return DracoonClientError::ConnectionFailed;
}

if value.is_connect() {
return DracoonClientError::ConnectionFailed;
}

DracoonClientError::Unknown
}
}



#[async_trait]
impl FromResponse for DracoonClientError {
async fn from_response(value: Response) -> Result<Self, DracoonClientError> {
Expand Down
Loading

0 comments on commit dfc0ee9

Please sign in to comment.