Skip to content

Commit

Permalink
Update handling protobuf error responses
Browse files Browse the repository at this point in the history
  • Loading branch information
pashinov committed Aug 26, 2023
1 parent b3af252 commit 8d17435
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions nekoton-transport/src/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 8d17435

Please sign in to comment.