Skip to content

Commit

Permalink
Merge remote-tracking branch 'github/feature/proto_errors'
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexagon committed Aug 27, 2023
2 parents b3af252 + 8d17435 commit d70dd09
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 d70dd09

Please sign in to comment.