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) server-digest SHA256) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id ECAB29F5B for ; Tue, 29 Aug 2023 14:04:41 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id D0C5E8F01 for ; Tue, 29 Aug 2023 14:04:41 +0200 (CEST) Received: from bookworm-dev.localdomain (unknown [94.136.29.99]) by firstgate.proxmox.com (Proxmox) with ESMTP for ; Tue, 29 Aug 2023 14:04:40 +0200 (CEST) Received: by bookworm-dev.localdomain (Postfix, from userid 1000) id 6B990604BF; Tue, 29 Aug 2023 14:04:40 +0200 (CEST) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Tue, 29 Aug 2023 14:04:40 +0200 Message-Id: <20230829120440.478630-1-d.csapak@proxmox.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.386 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RDNS_NONE 0.793 Delivered to internal network by a host with no rDNS 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. [lib.rs] Subject: [pbs-devel] [PATCH proxmox] client: remove option from inner RawApiResponse 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, 29 Aug 2023 12:04:42 -0000 when using the client for an api call that does not return any data (it returns '{"data":null}'), we would always get an error 'api returned no data'. The message is technically correct, but it should not be an error when we expect no data (e.g. most of our CRUD PUT/POST calls) instead of having the Option in the RawApiResponse type itself, move it into to the 'nodata' function intended for api calls where we don't expect any data. Signed-off-by: Dominik Csapak --- proxmox-client/src/lib.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/proxmox-client/src/lib.rs b/proxmox-client/src/lib.rs index 6039ae5..9aa7144 100644 --- a/proxmox-client/src/lib.rs +++ b/proxmox-client/src/lib.rs @@ -106,8 +106,8 @@ impl HttpApiResponse { /// Expect that the API call did *not* return any data in the `data` field. pub fn nodata(self) -> Result<(), Error> { - let response = serde_json::from_slice::>(&self.body) - .map_err(|err| Error::bad_api("failed to parse api response", err))?; + let response = serde_json::from_slice::>>(&self.body) + .map_err(|err| Error::bad_api("unexpected api response", err))?; if response.data.is_some() { Err(Error::UnexpectedData) @@ -131,7 +131,7 @@ struct RawApiResponse { message: Option, #[serde(default, deserialize_with = "proxmox_login::parse::deserialize_bool")] success: Option, - data: Option, + data: T, #[serde(default)] errors: HashMap, @@ -164,9 +164,7 @@ impl RawApiResponse { let this = self.check_success()?; Ok(ApiResponseData { - data: this - .data - .ok_or_else(|| Error::BadApi("api returned no data".to_string(), None))?, + data: this.data, attribs: this.attribs, }) } -- 2.39.2