File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed
Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -7,5 +7,6 @@ pub enum RequestError {
77 RequestFailed ( String ) ,
88 ConnectionError ( String ) ,
99 InternalError ( String ) ,
10+ ServerError ( String ) ,
1011 GrpcError ( String ) ,
1112}
Original file line number Diff line number Diff line change 11use std:: { collections:: HashMap , sync:: Arc , time:: Duration } ;
22
33use crate :: requester:: error:: RequestError ;
4+ use http:: StatusCode ;
45use reqwest:: { header:: HeaderMap , Client , Method } ;
56
67use crate :: metrics:: metrics:: Metrics ;
@@ -82,7 +83,23 @@ impl<'a> Requester for HttpRequester<'a> {
8283 RequestError :: Network
8384 }
8485 } ) ?;
85- let _status = resp. status ( ) ;
86+ let status = resp. status ( ) ;
87+
88+ self . metrics . add_bytes_sent ( self . request_size ) . await ;
89+
90+ if status >= StatusCode :: BAD_REQUEST {
91+ let req_duration = start. elapsed ( ) ;
92+
93+ self . metrics
94+ . record_latency ( req_duration. as_micros ( ) . try_into ( ) . unwrap_or ( 0 ) )
95+ . await ;
96+
97+ return Err ( RequestError :: ServerError ( format ! (
98+ "Service returned {} status code" ,
99+ status
100+ ) ) ) ;
101+ }
102+
86103 let body = resp. bytes ( ) . await . map_err ( |e| {
87104 if e. is_timeout ( ) {
88105 RequestError :: Timeout
@@ -93,7 +110,6 @@ impl<'a> Requester for HttpRequester<'a> {
93110
94111 let response_size = body. len ( ) as u64 ;
95112 self . metrics . add_bytes_received ( response_size) . await ;
96- self . metrics . add_bytes_sent ( self . request_size ) . await ;
97113
98114 let req_duration = start. elapsed ( ) ;
99115
You can’t perform that action at this time.
0 commit comments