From 8d17435263469fa846822defd43e8da408dc70a8 Mon Sep 17 00:00:00 2001 From: Alexey Pashinov Date: Sat, 26 Aug 2023 19:15:09 +0200 Subject: [PATCH] Update handling protobuf error responses --- nekoton-transport/src/proto.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/nekoton-transport/src/proto.rs b/nekoton-transport/src/proto.rs index 5a7f58f66..3e23f8f70 100644 --- a/nekoton-transport/src/proto.rs +++ b/nekoton-transport/src/proto.rs @@ -49,12 +49,18 @@ impl nekoton::external::ProtoConnection for ProtoClient { } else { &self.base_url }; + let response = self.client.post(url.clone()).body(req.data).send().await?; - if response.status() != StatusCode::OK { - let msg = rpc::Error::decode(response.bytes().await?)?; - anyhow::bail!(msg.message) - } - Ok(response.bytes().await?.into()) + let res = match response.status() { + StatusCode::OK => response.bytes().await?.into(), + StatusCode::UNPROCESSABLE_ENTITY => { + let msg = rpc::Error::decode(response.bytes().await?)?; + anyhow::bail!(msg.message) + } + _ => anyhow::bail!(response.status().to_string()), + }; + + Ok(res) } }