mirror of
https://gitlab.com/famedly/conduit.git
synced 2025-06-27 16:35:59 +00:00
refactor: improve error processing for S3
This commit is contained in:
parent
a30e0537e4
commit
efe774b3c1
2 changed files with 6 additions and 11 deletions
|
@ -643,8 +643,8 @@ impl Service {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
if !resp.status().is_success() {
|
if !resp.status().is_success() {
|
||||||
warn!("S3 request error ({}):\n{}", sha256_hex, resp.text().await?);
|
error!("Failed to get file with sha256 hash of \"{}\" from S3 bucket: {}", sha256_hex, resp.text().await?);
|
||||||
return Err(Error::bad_s3_response("Cannot read media file"));
|
return Err(Error::BadS3Response("Failed to get media file from S3 bucket"));
|
||||||
}
|
}
|
||||||
|
|
||||||
resp.bytes().await?.to_vec()
|
resp.bytes().await?.to_vec()
|
||||||
|
@ -702,8 +702,8 @@ pub async fn create_file(sha256_hex: &str, file: &[u8]) -> Result<()> {
|
||||||
let resp = client.put(url).body(file.to_vec()).send().await?;
|
let resp = client.put(url).body(file.to_vec()).send().await?;
|
||||||
|
|
||||||
if !resp.status().is_success() {
|
if !resp.status().is_success() {
|
||||||
warn!("S3 request error ({}):\n{}", sha256_hex, resp.text().await?);
|
error!("Failed to upload file with sha256 hash of \"{}\" to S3 bucket: {}", sha256_hex, resp.text().await?);
|
||||||
return Err(Error::bad_s3_response("Cannot write media file"));
|
return Err(Error::BadS3Response("Failed to upload media file to S3 bucket"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -795,8 +795,8 @@ async fn delete_file(sha256_hex: &str) -> Result<()> {
|
||||||
let resp = client.delete(url).send().await?;
|
let resp = client.delete(url).send().await?;
|
||||||
|
|
||||||
if !resp.status().is_success() {
|
if !resp.status().is_success() {
|
||||||
warn!("S3 request error ({}):\n{}", sha256_hex, resp.text().await?);
|
error!("Failed to delete file with sha256 hash of \"{}\" from S3 bucket: {}", sha256_hex, resp.text().await?);
|
||||||
return Err(Error::bad_s3_response("Cannot delete media file"));
|
return Err(Error::BadS3Response("Failed to delete media file from S3 bucket"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,11 +93,6 @@ impl Error {
|
||||||
error!("BadConfig: {}", message);
|
error!("BadConfig: {}", message);
|
||||||
Self::BadConfig(message)
|
Self::BadConfig(message)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bad_s3_response(message: &'static str) -> Self {
|
|
||||||
info!("BadS3Response: {}", message);
|
|
||||||
Self::BadS3Response(message)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Error {
|
impl Error {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue