Skip to content

Commit

Permalink
feat(backends): allow disabling 2xx check
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaro00 committed Aug 20, 2024
1 parent c3a9b7a commit 38a58c9
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion backends/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ pub enum Error {
pub struct ServicesApiClient {
client: Client,
base: Uri,
/// Default true. Mutate to false to disable check.
pub error_on_non_2xx: bool,
}

impl ServicesApiClient {
Expand All @@ -47,6 +49,7 @@ impl ServicesApiClient {
Self {
client: Self::builder().build().unwrap(),
base,
error_on_non_2xx: true,
}
}

Expand All @@ -57,13 +60,15 @@ impl ServicesApiClient {
.build()
.unwrap(),
base,
error_on_non_2xx: true,
}
}

pub fn new_with_default_headers(base: Uri, headers: HeaderMap) -> Self {
Self {
client: Self::builder().default_headers(headers).build().unwrap(),
base,
error_on_non_2xx: true,
}
}

Expand Down Expand Up @@ -148,7 +153,7 @@ impl ServicesApiClient {
let resp = req.send().await?;
trace!(response = ?resp, "service response");

if !resp.status().is_success() {
if self.error_on_non_2xx && !resp.status().is_success() {
return Err(Error::RequestError(resp.status()));
}

Expand Down

0 comments on commit 38a58c9

Please sign in to comment.