fix(server) `fs/download` handle panic
This commit is contained in:
parent
c745b9db96
commit
cca7dd3efd
|
@ -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)
|
||||
|
|
|
@ -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),
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue