@@ -25,9 +25,9 @@ use std::str::FromStr;
25
25
use crate :: api:: AddressStats ;
26
26
use crate :: {
27
27
BlockStatus , BlockSummary , Builder , Error , MerkleProof , OutputStatus , Tx , TxStatus ,
28
- BASE_BACKOFF_MILLIS , RETRYABLE_ERROR_CODES ,
28
+ BASE_BACKOFF_MILLIS , RETRYABLE_ERROR_CODES , VALID_HTTP_CODE
29
29
} ;
30
- use async_minreq:: { Method , Request } ;
30
+ use async_minreq:: { Method , Request , Response } ;
31
31
#[ allow( unused_imports) ]
32
32
use log:: { debug, error, info, trace} ;
33
33
@@ -77,7 +77,7 @@ impl<S: Sleeper> AsyncClient<S> {
77
77
let url = format ! ( "{}{}" , self . url, path) ;
78
78
let response = self . get_with_retry ( & url) . await ?;
79
79
80
- if response. status_code > 299 {
80
+ if response. status_code > VALID_HTTP_CODE {
81
81
return Err ( Error :: HttpResponse {
82
82
status : response. status_code as u16 ,
83
83
message : match response. as_str ( ) {
@@ -120,7 +120,7 @@ impl<S: Sleeper> AsyncClient<S> {
120
120
let url = format ! ( "{}{}" , self . url, path) ;
121
121
let response = self . get_with_retry ( & url) . await ?;
122
122
123
- if response. status_code > 299 {
123
+ if response. status_code > VALID_HTTP_CODE {
124
124
return Err ( Error :: HttpResponse {
125
125
status : response. status_code as u16 ,
126
126
message : match response. as_str ( ) {
@@ -129,11 +129,7 @@ impl<S: Sleeper> AsyncClient<S> {
129
129
} ,
130
130
} ) ;
131
131
}
132
- serde_json:: from_str ( match response. as_str ( ) {
133
- Ok ( resp) => resp,
134
- Err ( _) => return Err ( Error :: InvalidResponse ) ,
135
- } )
136
- . map_err ( Error :: Json )
132
+ response. json ( ) . map_err ( Error :: AsyncMinreq )
137
133
}
138
134
139
135
/// Make an HTTP GET request to given URL, deserializing to `Option<T>`.
@@ -168,7 +164,7 @@ impl<S: Sleeper> AsyncClient<S> {
168
164
let url = format ! ( "{}{}" , self . url, path) ;
169
165
let response = self . get_with_retry ( & url) . await ?;
170
166
171
- if response. status_code > 299 {
167
+ if response. status_code > VALID_HTTP_CODE {
172
168
return Err ( Error :: HttpResponse {
173
169
status : response. status_code as u16 ,
174
170
message : match response. as_str ( ) {
@@ -210,7 +206,7 @@ impl<S: Sleeper> AsyncClient<S> {
210
206
let url = format ! ( "{}{}" , self . url, path) ;
211
207
let response = self . get_with_retry ( & url) . await ?;
212
208
213
- if response. status_code > 299 {
209
+ if response. status_code > VALID_HTTP_CODE {
214
210
return Err ( Error :: HttpResponse {
215
211
status : response. status_code as u16 ,
216
212
message : match response. as_str ( ) {
@@ -259,7 +255,7 @@ impl<S: Sleeper> AsyncClient<S> {
259
255
}
260
256
261
257
let response = request. send ( ) . await . map_err ( Error :: AsyncMinreq ) ?;
262
- if response. status_code > 299 {
258
+ if response. status_code > VALID_HTTP_CODE {
263
259
return Err ( Error :: HttpResponse {
264
260
status : response. status_code as u16 ,
265
261
message : match response. as_str ( ) {
@@ -280,7 +276,7 @@ impl<S: Sleeper> AsyncClient<S> {
280
276
pub async fn get_tx_no_opt ( & self , txid : & Txid ) -> Result < Transaction , Error > {
281
277
match self . get_tx ( txid) . await {
282
278
Ok ( Some ( tx) ) => Ok ( tx) ,
283
- Ok ( None ) => Err ( Error :: TransactionNotFound ( * txid) ) , //look into
279
+ Ok ( None ) => Err ( Error :: TransactionNotFound ( * txid) ) ,
284
280
Err ( e) => Err ( e) ,
285
281
}
286
282
}
@@ -452,7 +448,7 @@ impl<S: Sleeper> AsyncClient<S> {
452
448
453
449
/// Sends a GET request to the given `url`, retrying failed attempts
454
450
/// for retryable error codes until max retries hit.
455
- async fn get_with_retry ( & self , url : & str ) -> Result < async_minreq :: Response , Error > {
451
+ async fn get_with_retry ( & self , url : & str ) -> Result < Response , Error > {
456
452
let mut delay = BASE_BACKOFF_MILLIS ;
457
453
let mut attempts = 0 ;
458
454
0 commit comments