api: translate ENOTFOUND to 404 for downloads

and percolate the HttpError back up on the client side

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
Fabian Grünbichler
2020-07-21 15:03:34 +02:00
committed by Thomas Lamprecht
parent 86f6f74114
commit 91f5594c08
2 changed files with 9 additions and 3 deletions

View File

@ -6,7 +6,12 @@ use proxmox::http_err;
pub async fn create_download_response(path: PathBuf) -> Result<Response<Body>, Error> {
let file = tokio::fs::File::open(path.clone())
.map_err(move |err| http_err!(BAD_REQUEST, format!("open file {:?} failed: {}", path.clone(), err)))
.map_err(move |err| {
match err.kind() {
std::io::ErrorKind::NotFound => http_err!(NOT_FOUND, format!("open file {:?} failed - not found", path.clone())),
_ => http_err!(BAD_REQUEST, format!("open file {:?} failed: {}", path.clone(), err)),
}
})
.await?;
let payload = tokio_util::codec::FramedRead::new(file, tokio_util::codec::BytesCodec::new())