diff --git a/server/src/fs/download.rs b/server/src/fs/download.rs index 657c547..9e5473a 100644 --- a/server/src/fs/download.rs +++ b/server/src/fs/download.rs @@ -3,6 +3,7 @@ use std::fs; use axum::{extract::Query, Extension}; use axum_auth::AuthBearer; use homedisk_database::Database; +use homedisk_types::errors::FsError; use homedisk_types::fs::upload::Pagination; use homedisk_types::{config::Config, errors::ServerError}; @@ -33,7 +34,8 @@ pub async fn handle( ); // read file content - let content = fs::read(path).unwrap(); + let content = + fs::read(path).map_err(|err| ServerError::FsError(FsError::ReadFile(err.to_string())))?; // send file content in Response Ok(content) diff --git a/types/src/errors/fs.rs b/types/src/errors/fs.rs index 1dafa04..9b20dfc 100644 --- a/types/src/errors/fs.rs +++ b/types/src/errors/fs.rs @@ -23,6 +23,8 @@ pub enum Error { Base64(String), #[error("failed to read directory: {0}")] ReadDirectory(String), + #[error("failed to read file content: {0}")] + ReadFile(String), #[error("other error - {0}")] Other(String), }