From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id CF33864F53 for ; Tue, 21 Jul 2020 15:03:51 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id CCFD218D03 for ; Tue, 21 Jul 2020 15:03:51 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 4FB8E18CF9 for ; Tue, 21 Jul 2020 15:03:51 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 1DFAF40777 for ; Tue, 21 Jul 2020 15:03:51 +0200 (CEST) From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= To: pbs-devel@lists.proxmox.com Date: Tue, 21 Jul 2020 15:03:34 +0200 Message-Id: <20200721130337.934653-4-f.gruenbichler@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200721130337.934653-1-f.gruenbichler@proxmox.com> References: <20200721130337.934653-1-f.gruenbichler@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.081 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [helpers.rs] Subject: [pbs-devel] [PATCH proxmox-backup 3/6] api: translate ENOTFOUND to 404 for downloads X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Jul 2020 13:03:51 -0000 and percolate the HttpError back up on the client side Signed-off-by: Fabian Grünbichler --- src/api2/helpers.rs | 7 ++++++- src/client/http_client.rs | 5 +++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/api2/helpers.rs b/src/api2/helpers.rs index 9dd4ecba..a3c68087 100644 --- a/src/api2/helpers.rs +++ b/src/api2/helpers.rs @@ -6,7 +6,12 @@ use proxmox::http_err; pub async fn create_download_response(path: PathBuf) -> Result, 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()) diff --git a/src/client/http_client.rs b/src/client/http_client.rs index 3886c40f..a930ea56 100644 --- a/src/client/http_client.rs +++ b/src/client/http_client.rs @@ -16,6 +16,7 @@ use percent_encoding::percent_encode; use xdg::BaseDirectories; use proxmox::{ + api::error::HttpError, sys::linux::tty, tools::{ fs::{file_get_json, replace_file, CreateOptions}, @@ -606,7 +607,7 @@ impl HttpClient { Ok(value) } } else { - bail!("HTTP Error {}: {}", status, text); + Err(Error::from(HttpError::new(status, text))) } } @@ -819,7 +820,7 @@ impl H2Client { bail!("got result without data property"); } } else { - bail!("HTTP Error {}: {}", status, text); + Err(Error::from(HttpError::new(status, text))) } } -- 2.20.1