Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Cargo.lock

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

Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ pub async fn {{ operation.rust_function_name }}(
match content_type {
ContentType::Json => {
let content = resp.text().await?;
serde_json::from_str(&content).map_err(Error::from)
serde_path_to_error::deserialize(&mut serde_json::Deserializer::from_str(&content)).map_err(Error::from)
},
ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `{{ get_success_response_type(operation) }}`"))),
ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `{{ get_success_response_type(operation) }}`")))),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,9 @@ pub async fn {{ operation.rust_function_name }}(
.unwrap_or("application/json");

match ContentType::from(content_type) {
ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde { message: e.to_string() }),
ContentType::Json => serde_path_to_error::deserialize(&mut serde_json::Deserializer::from_slice(&response.body)).map_err(|e| Error::Serde { message: e.to_string() }),
{% if operation.supports_msgpack %}
ContentType::MsgPack => rmp_serde::from_slice(&response.body).map_err(|e| Error::Serde { message: e.to_string() }),
ContentType::MsgPack => serde_path_to_error::deserialize(&mut rmp_serde::Deserializer::new(std::io::Cursor::new(&response.body))).map_err(|e| Error::Serde { message: e.to_string() }),
{% else %}
ContentType::MsgPack => Err(Error::Serde { message: "MsgPack not supported".to_string() }),
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ serde_with = { version = "^3.8", default-features = false, features = [
"macros",
] }
serde_json = "^1.0"
serde_path_to_error = "^0.1"
serde_repr = "^0.1"
serde_bytes = "^0.11"

Expand Down
1 change: 1 addition & 0 deletions crates/algod_client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ serde_with = { version = "^3.8", default-features = false, features = [
"macros",
] }
serde_json = "^1.0"
serde_path_to_error = "^0.1"
serde_repr = "^0.1"
serde_bytes = "^0.11"

Expand Down
5 changes: 4 additions & 1 deletion crates/algod_client/src/apis/abort_catchup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ pub async fn abort_catchup(
.unwrap_or("application/json");

match ContentType::from(content_type) {
ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde {
ContentType::Json => serde_path_to_error::deserialize(
&mut serde_json::Deserializer::from_slice(&response.body),
)
.map_err(|e| Error::Serde {
message: e.to_string(),
}),
ContentType::MsgPack => Err(Error::Serde {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,16 @@ pub async fn account_application_information(
.unwrap_or("application/json");

match ContentType::from(content_type) {
ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde {
ContentType::Json => serde_path_to_error::deserialize(
&mut serde_json::Deserializer::from_slice(&response.body),
)
.map_err(|e| Error::Serde {
message: e.to_string(),
}),
ContentType::MsgPack => rmp_serde::from_slice(&response.body).map_err(|e| Error::Serde {
ContentType::MsgPack => serde_path_to_error::deserialize(
&mut rmp_serde::Deserializer::new(std::io::Cursor::new(&response.body)),
)
.map_err(|e| Error::Serde {
message: e.to_string(),
}),
ContentType::Text => {
Expand Down
5 changes: 4 additions & 1 deletion crates/algod_client/src/apis/account_asset_information.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ pub async fn account_asset_information(
.unwrap_or("application/json");

match ContentType::from(content_type) {
ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde {
ContentType::Json => serde_path_to_error::deserialize(
&mut serde_json::Deserializer::from_slice(&response.body),
)
.map_err(|e| Error::Serde {
message: e.to_string(),
}),
ContentType::MsgPack => Err(Error::Serde {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ pub async fn account_assets_information(
.unwrap_or("application/json");

match ContentType::from(content_type) {
ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde {
ContentType::Json => serde_path_to_error::deserialize(
&mut serde_json::Deserializer::from_slice(&response.body),
)
.map_err(|e| Error::Serde {
message: e.to_string(),
}),
ContentType::MsgPack => Err(Error::Serde {
Expand Down
5 changes: 4 additions & 1 deletion crates/algod_client/src/apis/account_information.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ pub async fn account_information(
.unwrap_or("application/json");

match ContentType::from(content_type) {
ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde {
ContentType::Json => serde_path_to_error::deserialize(
&mut serde_json::Deserializer::from_slice(&response.body),
)
.map_err(|e| Error::Serde {
message: e.to_string(),
}),
ContentType::MsgPack => Err(Error::Serde {
Expand Down
10 changes: 8 additions & 2 deletions crates/algod_client/src/apis/add_participation_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,16 @@ pub async fn add_participation_key(
.unwrap_or("application/json");

match ContentType::from(content_type) {
ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde {
ContentType::Json => serde_path_to_error::deserialize(
&mut serde_json::Deserializer::from_slice(&response.body),
)
.map_err(|e| Error::Serde {
message: e.to_string(),
}),
ContentType::MsgPack => rmp_serde::from_slice(&response.body).map_err(|e| Error::Serde {
ContentType::MsgPack => serde_path_to_error::deserialize(
&mut rmp_serde::Deserializer::new(std::io::Cursor::new(&response.body)),
)
.map_err(|e| Error::Serde {
message: e.to_string(),
}),
ContentType::Text => {
Expand Down
10 changes: 8 additions & 2 deletions crates/algod_client/src/apis/append_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,16 @@ pub async fn append_keys(
.unwrap_or("application/json");

match ContentType::from(content_type) {
ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde {
ContentType::Json => serde_path_to_error::deserialize(
&mut serde_json::Deserializer::from_slice(&response.body),
)
.map_err(|e| Error::Serde {
message: e.to_string(),
}),
ContentType::MsgPack => rmp_serde::from_slice(&response.body).map_err(|e| Error::Serde {
ContentType::MsgPack => serde_path_to_error::deserialize(
&mut rmp_serde::Deserializer::new(std::io::Cursor::new(&response.body)),
)
.map_err(|e| Error::Serde {
message: e.to_string(),
}),
ContentType::Text => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ pub async fn generate_participation_keys(
.unwrap_or("application/json");

match ContentType::from(content_type) {
ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde {
ContentType::Json => serde_path_to_error::deserialize(
&mut serde_json::Deserializer::from_slice(&response.body),
)
.map_err(|e| Error::Serde {
message: e.to_string(),
}),
ContentType::MsgPack => Err(Error::Serde {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ pub async fn get_application_box_by_name(
.unwrap_or("application/json");

match ContentType::from(content_type) {
ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde {
ContentType::Json => serde_path_to_error::deserialize(
&mut serde_json::Deserializer::from_slice(&response.body),
)
.map_err(|e| Error::Serde {
message: e.to_string(),
}),
ContentType::MsgPack => Err(Error::Serde {
Expand Down
5 changes: 4 additions & 1 deletion crates/algod_client/src/apis/get_application_boxes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ pub async fn get_application_boxes(
.unwrap_or("application/json");

match ContentType::from(content_type) {
ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde {
ContentType::Json => serde_path_to_error::deserialize(
&mut serde_json::Deserializer::from_slice(&response.body),
)
.map_err(|e| Error::Serde {
message: e.to_string(),
}),
ContentType::MsgPack => Err(Error::Serde {
Expand Down
5 changes: 4 additions & 1 deletion crates/algod_client/src/apis/get_application_by_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ pub async fn get_application_by_id(
.unwrap_or("application/json");

match ContentType::from(content_type) {
ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde {
ContentType::Json => serde_path_to_error::deserialize(
&mut serde_json::Deserializer::from_slice(&response.body),
)
.map_err(|e| Error::Serde {
message: e.to_string(),
}),
ContentType::MsgPack => Err(Error::Serde {
Expand Down
5 changes: 4 additions & 1 deletion crates/algod_client/src/apis/get_asset_by_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ pub async fn get_asset_by_id(http_client: &dyn HttpClient, asset_id: u64) -> Res
.unwrap_or("application/json");

match ContentType::from(content_type) {
ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde {
ContentType::Json => serde_path_to_error::deserialize(
&mut serde_json::Deserializer::from_slice(&response.body),
)
.map_err(|e| Error::Serde {
message: e.to_string(),
}),
ContentType::MsgPack => Err(Error::Serde {
Expand Down
10 changes: 8 additions & 2 deletions crates/algod_client/src/apis/get_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,16 @@ pub async fn get_block(
.unwrap_or("application/json");

match ContentType::from(content_type) {
ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde {
ContentType::Json => serde_path_to_error::deserialize(
&mut serde_json::Deserializer::from_slice(&response.body),
)
.map_err(|e| Error::Serde {
message: e.to_string(),
}),
ContentType::MsgPack => rmp_serde::from_slice(&response.body).map_err(|e| Error::Serde {
ContentType::MsgPack => serde_path_to_error::deserialize(
&mut rmp_serde::Deserializer::new(std::io::Cursor::new(&response.body)),
)
.map_err(|e| Error::Serde {
message: e.to_string(),
}),
ContentType::Text => {
Expand Down
5 changes: 4 additions & 1 deletion crates/algod_client/src/apis/get_block_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ pub async fn get_block_hash(
.unwrap_or("application/json");

match ContentType::from(content_type) {
ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde {
ContentType::Json => serde_path_to_error::deserialize(
&mut serde_json::Deserializer::from_slice(&response.body),
)
.map_err(|e| Error::Serde {
message: e.to_string(),
}),
ContentType::MsgPack => Err(Error::Serde {
Expand Down
5 changes: 4 additions & 1 deletion crates/algod_client/src/apis/get_block_logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ pub async fn get_block_logs(
.unwrap_or("application/json");

match ContentType::from(content_type) {
ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde {
ContentType::Json => serde_path_to_error::deserialize(
&mut serde_json::Deserializer::from_slice(&response.body),
)
.map_err(|e| Error::Serde {
message: e.to_string(),
}),
ContentType::MsgPack => Err(Error::Serde {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ pub async fn get_block_time_stamp_offset(
.unwrap_or("application/json");

match ContentType::from(content_type) {
ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde {
ContentType::Json => serde_path_to_error::deserialize(
&mut serde_json::Deserializer::from_slice(&response.body),
)
.map_err(|e| Error::Serde {
message: e.to_string(),
}),
ContentType::MsgPack => Err(Error::Serde {
Expand Down
5 changes: 4 additions & 1 deletion crates/algod_client/src/apis/get_block_txids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ pub async fn get_block_txids(
.unwrap_or("application/json");

match ContentType::from(content_type) {
ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde {
ContentType::Json => serde_path_to_error::deserialize(
&mut serde_json::Deserializer::from_slice(&response.body),
)
.map_err(|e| Error::Serde {
message: e.to_string(),
}),
ContentType::MsgPack => Err(Error::Serde {
Expand Down
5 changes: 4 additions & 1 deletion crates/algod_client/src/apis/get_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ pub async fn get_config(http_client: &dyn HttpClient) -> Result<String, Error> {
.unwrap_or("application/json");

match ContentType::from(content_type) {
ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde {
ContentType::Json => serde_path_to_error::deserialize(
&mut serde_json::Deserializer::from_slice(&response.body),
)
.map_err(|e| Error::Serde {
message: e.to_string(),
}),
ContentType::MsgPack => Err(Error::Serde {
Expand Down
5 changes: 4 additions & 1 deletion crates/algod_client/src/apis/get_debug_settings_prof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ pub async fn get_debug_settings_prof(
.unwrap_or("application/json");

match ContentType::from(content_type) {
ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde {
ContentType::Json => serde_path_to_error::deserialize(
&mut serde_json::Deserializer::from_slice(&response.body),
)
.map_err(|e| Error::Serde {
message: e.to_string(),
}),
ContentType::MsgPack => Err(Error::Serde {
Expand Down
5 changes: 4 additions & 1 deletion crates/algod_client/src/apis/get_genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ pub async fn get_genesis(http_client: &dyn HttpClient) -> Result<Genesis, Error>
.unwrap_or("application/json");

match ContentType::from(content_type) {
ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde {
ContentType::Json => serde_path_to_error::deserialize(
&mut serde_json::Deserializer::from_slice(&response.body),
)
.map_err(|e| Error::Serde {
message: e.to_string(),
}),
ContentType::MsgPack => Err(Error::Serde {
Expand Down
10 changes: 8 additions & 2 deletions crates/algod_client/src/apis/get_ledger_state_delta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,16 @@ pub async fn get_ledger_state_delta(
.unwrap_or("application/json");

match ContentType::from(content_type) {
ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde {
ContentType::Json => serde_path_to_error::deserialize(
&mut serde_json::Deserializer::from_slice(&response.body),
)
.map_err(|e| Error::Serde {
message: e.to_string(),
}),
ContentType::MsgPack => rmp_serde::from_slice(&response.body).map_err(|e| Error::Serde {
ContentType::MsgPack => serde_path_to_error::deserialize(
&mut rmp_serde::Deserializer::new(std::io::Cursor::new(&response.body)),
)
.map_err(|e| Error::Serde {
message: e.to_string(),
}),
ContentType::Text => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,16 @@ pub async fn get_ledger_state_delta_for_transaction_group(
.unwrap_or("application/json");

match ContentType::from(content_type) {
ContentType::Json => serde_json::from_slice(&response.body).map_err(|e| Error::Serde {
ContentType::Json => serde_path_to_error::deserialize(
&mut serde_json::Deserializer::from_slice(&response.body),
)
.map_err(|e| Error::Serde {
message: e.to_string(),
}),
ContentType::MsgPack => rmp_serde::from_slice(&response.body).map_err(|e| Error::Serde {
ContentType::MsgPack => serde_path_to_error::deserialize(
&mut rmp_serde::Deserializer::new(std::io::Cursor::new(&response.body)),
)
.map_err(|e| Error::Serde {
message: e.to_string(),
}),
ContentType::Text => {
Expand Down
Loading