From ca76b67e985583ebc4276d6dce9dc74fde3af3bc Mon Sep 17 00:00:00 2001 From: Vika Date: Tue, 3 Dec 2024 08:29:38 +0300 Subject: kittybox-util: bump to 0.3.0 Changed micropub::Error's description to Option> to allow for that sweet sweet memory savings from not having to heap-allocate strings for static errors. Change-Id: Ic82e5ad5cacea766ea0a7e8677ce6a7f16ae8668 --- src/media/mod.rs | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'src/media/mod.rs') diff --git a/src/media/mod.rs b/src/media/mod.rs index 32b8405..3ed6810 100644 --- a/src/media/mod.rs +++ b/src/media/mod.rs @@ -13,10 +13,10 @@ pub use storage::file::FileStore; impl From for MicropubError { fn from(err: MediaStoreError) -> Self { - Self { - error: ErrorType::InternalServerError, - error_description: format!("{}", err) - } + Self::new( + ErrorType::InternalServerError, + format!("media store error: {}", err) + ) } } @@ -27,25 +27,25 @@ pub(crate) async fn upload( mut upload: Multipart ) -> Response { if !user.check_scope(&Scope::Media) { - return MicropubError { - error: ErrorType::NotAuthorized, - error_description: "Interacting with the media storage requires the \"media\" scope.".to_owned() - }.into_response(); + return MicropubError::from_static( + ErrorType::NotAuthorized, + "Interacting with the media storage requires the \"media\" scope." + ).into_response(); } let host = user.me.authority(); let field = match upload.next_field().await { Ok(Some(field)) => field, Ok(None) => { - return MicropubError { - error: ErrorType::InvalidRequest, - error_description: "Send multipart/form-data with one field named file".to_owned() - }.into_response(); + return MicropubError::from_static( + ErrorType::InvalidRequest, + "Send multipart/form-data with one field named file" + ).into_response(); }, Err(err) => { - return MicropubError { - error: ErrorType::InternalServerError, - error_description: format!("Error while parsing multipart/form-data: {}", err) - }.into_response(); + return MicropubError::new( + ErrorType::InternalServerError, + format!("Error while parsing multipart/form-data: {}", err) + ).into_response(); }, }; let metadata: Metadata = (&field).into(); -- cgit 1.4.1