fix(server) `fs/download` handle panic

This commit is contained in:
MedzikUser 2022-07-12 22:15:27 +02:00
parent c745b9db96
commit cca7dd3efd
No known key found for this signature in database
GPG Key ID: A5FAC1E185C112DB
2 changed files with 5 additions and 1 deletions

View File

@ -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)

View File

@ -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),
}