From daf8dc3c93727288e2b705abb44f22b23c16ed70 Mon Sep 17 00:00:00 2001 From: Abdulla Abdurakhmanov Date: Mon, 5 Aug 2024 14:02:21 +0200 Subject: [PATCH] Error handling update --- src/errors.rs | 42 +++++++++++++++++------------------------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/src/errors.rs b/src/errors.rs index 1034196..ee62e58 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -1,7 +1,3 @@ -use gcloud_sdk::google_rest_apis::storage_v1::objects_api::{ - StoragePeriodObjectsPeriodGetError, StoragePeriodObjectsPeriodInsertError, - StoragePeriodObjectsPeriodListError, -}; use gcloud_sdk::tonic::metadata::errors::InvalidMetadataValue; use thiserror::Error; @@ -15,35 +11,23 @@ pub enum AppError { InputOutputError(#[from] std::io::Error), #[error("Destination '{destination}' doesn't support multiple files. Trailing slash needed?")] DestinationDoesNotSupportMultipleFiles { destination: String }, - #[error("Google Cloud SDK error")] + #[error("Google Cloud REST SDK error:\n{0}")] GoogleCloudRestSdkError(#[from] gcloud_sdk::error::Error), - #[error("Google Cloud Storage download error")] - GoogleCloudStorageGetObjectError( - #[from] gcloud_sdk::google_rest_apis::storage_v1::Error, - ), - #[error("Google Cloud Storage upload error")] - GoogleCloudStorageInsertObjectError( - #[from] - gcloud_sdk::google_rest_apis::storage_v1::Error, - ), - #[error("Google Cloud Storage upload error")] - GoogleCloudStorageListObjectError( - #[from] - gcloud_sdk::google_rest_apis::storage_v1::Error, - ), - #[error("Google Cloud SDK error")] + #[error("Google Cloud REST SDK API error:\n{0:?}")] + GoogleCloudRestSdkApiError(Box), + #[error("Google Cloud SDK error:\n{0}")] GoogleCloudGrpcError(#[from] gcloud_sdk::tonic::Status), - #[error("Google Cloud invalid metadata value")] + #[error("Google Cloud invalid metadata value:\n{0}")] GoogleCloudInvalidMetadataValue(#[from] InvalidMetadataValue), #[error("AWS SDK error occurred")] AwsSdkError(#[from] Box), - #[error("MIME error")] + #[error("MIME error:\n{0}")] MimeError(#[from] mime::FromStrError), - #[error("HTTP client error")] + #[error("HTTP client error:\n{0}")] HttpClientError(#[from] reqwest::Error), - #[error("Zip error")] + #[error("Zip error:\n{0}")] ZipError(#[from] zip::result::ZipError), - #[error("CSV parser error")] + #[error("CSV parser error:\n{0}")] CsvParserError(#[from] csv_async::Error), #[error("Redacter config error: {message}")] RedacterConfigError { message: String }, @@ -60,3 +44,11 @@ impl< Self::AwsSdkError(Box::new(err)) } } + +impl + From> for AppError +{ + fn from(err: gcloud_sdk::google_rest_apis::storage_v1::Error) -> Self { + Self::GoogleCloudRestSdkApiError(Box::new(err)) + } +}