Skip to content

Commit 41a1026

Browse files
committed
chore: fix 4145 by returning the JSON representation of a fee estimator error
1 parent c94f473 commit 41a1026

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

stackslib/src/net/api/postfeerate.rs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use std::io::{Read, Write};
1818

1919
use clarity::vm::costs::ExecutionCost;
2020
use regex::{Captures, Regex};
21+
use serde_json::json;
2122
use stacks_common::codec::{StacksMessageCodec, MAX_PAYLOAD_LEN};
2223
use stacks_common::types::chainstate::{
2324
BlockHeaderHash, ConsensusHash, StacksBlockId, StacksPublicKey,
@@ -118,13 +119,7 @@ impl RPCPostFeeRateRequestHandler {
118119
let scalar_cost =
119120
metric.from_cost_and_len(&estimated_cost, &stacks_epoch.block_limit, estimated_len);
120121
let fee_rates = fee_estimator.get_rate_estimates().map_err(|e| {
121-
StacksHttpResponse::new_error(
122-
preamble,
123-
&HttpBadRequest::new(format!(
124-
"Estimator RPC endpoint failed to estimate fees for tx: {:?}",
125-
&e
126-
)),
127-
)
122+
StacksHttpResponse::new_error(preamble, &HttpBadRequest::new_json(e.into_json()))
128123
})?;
129124

130125
let mut estimations = RPCFeeEstimate::estimate_fees(scalar_cost, fee_rates).to_vec();
@@ -243,11 +238,7 @@ impl RPCRequestHandler for RPCPostFeeRateRequestHandler {
243238
.map_err(|e| {
244239
StacksHttpResponse::new_error(
245240
&preamble,
246-
&HttpBadRequest::new(format!(
247-
"Estimator RPC endpoint failed to estimate tx {}: {:?}",
248-
&tx.name(),
249-
&e
250-
)),
241+
&HttpBadRequest::new_json(e.into_json()),
251242
)
252243
})?;
253244

@@ -263,9 +254,9 @@ impl RPCRequestHandler for RPCPostFeeRateRequestHandler {
263254
debug!("Fee and cost estimation not configured on this stacks node");
264255
Err(StacksHttpResponse::new_error(
265256
&preamble,
266-
&HttpBadRequest::new(
267-
"Fee estimation not supported on this node".to_string(),
268-
),
257+
&HttpBadRequest::new_json(json!(
258+
"Fee estimation not supported on this node"
259+
)),
269260
))
270261
}
271262
});

0 commit comments

Comments
 (0)