Skip to content

Commit

Permalink
Merge pull request #345 from yoshidan/fix/change_sign_error_response
Browse files Browse the repository at this point in the history
Fix sign_url error response
  • Loading branch information
yoshidan authored Feb 1, 2025
2 parents 28c1bb3 + 2f38831 commit adf80d3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
3 changes: 2 additions & 1 deletion deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ allow = [
"BSD-2-Clause",
"BSD-3-Clause",
"CC0-1.0",
"Unicode-3.0"
"Unicode-3.0",
"Zlib",
]
# The confidence threshold for detecting a license from license text.
# The higher the value, the more closely the license text must be to the
Expand Down
3 changes: 3 additions & 0 deletions storage/src/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ pub enum Error {
/// Invalid Range error
#[error("invalid range header, received: {0}")]
InvalidRangeHeader(String),

#[error("Request failed: {0} detail={1}")]
RawResponse(reqwest::Error, String),
}

impl From<reqwest_middleware::Error> for Error {
Expand Down
20 changes: 16 additions & 4 deletions storage/src/http/service_account_client.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::sync::Arc;

use google_cloud_token::TokenSource;
use reqwest::Response;
use std::sync::Arc;

use crate::http::{check_response_status, Error};
use crate::http::Error;

#[derive(Clone)]
pub struct ServiceAccountClient {
Expand Down Expand Up @@ -42,9 +42,21 @@ impl ServiceAccountClient {
None => request,
};
let response = request.send().await?;
let response = check_response_status(response).await?;
let response = ServiceAccountClient::check_response_status(response).await?;
Ok(response.json::<SignBlobResponse>().await?.signed_blob)
}

/// Checks whether an HTTP response is successful and returns it, or returns an error.
async fn check_response_status(response: Response) -> Result<Response, Error> {
// Check the status code, returning the response if it is not an error.
match response.error_for_status_ref() {
Ok(_) => Ok(response),
Err(error) => match response.text().await {
Ok(raw) => Err(Error::RawResponse(error, raw)),
Err(_) => Err(Error::HttpClient(error)),
},
}
}
}

#[derive(serde::Serialize)]
Expand Down

0 comments on commit adf80d3

Please sign in to comment.