Skip to content

Commit

Permalink
Make AptosErrorCode compatible with serde deserialization (aptos-labs…
Browse files Browse the repository at this point in the history
  • Loading branch information
banool authored Aug 16, 2022
1 parent 0f0cd2d commit 64254a4
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions api/types/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ impl From<anyhow::Error> for AptosError {
// Make sure the integer codes increment one by one.
#[derive(Debug, Deserialize, Enum)]
#[oai(rename_all = "snake_case")]
#[serde(rename_all = "snake_case")]
pub enum AptosErrorCode {
/// The API failed to read from storage for this request, not because of a
/// bad request, but because of some internal error.
Expand Down
1 change: 1 addition & 0 deletions crates/aptos-rest-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ dpn = []
anyhow = "1.0.57"
bcs = "0.1.3"
hex = "0.4.3"
poem-openapi = { git = "https://github.com/poem-web/poem", rev = "f39eba95cbfb52989e0eff516dad86719dc7dcba", features = ["url"] }
reqwest = { version = "0.11.10", features = ["json", "cookies", "blocking"] }
serde = { version = "1.0.137", features = ["derive"] }
serde_json = "1.0.81"
Expand Down
5 changes: 3 additions & 2 deletions crates/aptos-rest-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use aptos_types::{
account_config::{NewBlockEvent, CORE_CODE_ADDRESS},
transaction::SignedTransaction,
};
use poem_openapi::types::ParseFromJSON;
use reqwest::{header::CONTENT_TYPE, Client as ReqwestClient, StatusCode};
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use serde_json::{json, Value};
Expand Down Expand Up @@ -510,7 +511,7 @@ impl Client {
let response = self.inner.get(url.clone()).send().await?;

if !response.status().is_success() {
let error_response = response.json::<AptosError>().await?;
let error_response = AptosError::parse_from_json(Some(response.json().await?));
return Err(anyhow::anyhow!("Request failed: {:?}", error_response));
}

Expand All @@ -525,7 +526,7 @@ impl Client {
response: reqwest::Response,
) -> Result<(reqwest::Response, State)> {
if !response.status().is_success() {
let error_response = response.json::<AptosError>().await?;
let error_response = AptosError::parse_from_json(Some(response.json().await?));
return Err(anyhow::anyhow!("Request failed: {:?}", error_response));
}
let state = State::from_headers(response.headers())?;
Expand Down

0 comments on commit 64254a4

Please sign in to comment.