@@ -36,29 +36,25 @@ pub fn load_jwt_secrets() -> Result<HashMap<ModuleId, String>> {
3636pub async fn safe_read_http_response ( response : reqwest:: Response ) -> Result < Vec < u8 > > {
3737 // Read the response to a buffer in chunks
3838 let status_code = response. status ( ) ;
39- let response_bytes = read_chunked_body_with_max ( response, MUXER_HTTP_MAX_LENGTH )
40- . await ?;
41-
42- // Make sure the response is a 200
43- if status_code != reqwest:: StatusCode :: OK {
44- match response_bytes {
45- Ok ( bytes) => {
46- bail ! (
47- "Request failed with status: {}, body: {}" ,
48- status_code,
49- String :: from_utf8_lossy( & bytes)
50- ) ;
39+ match read_chunked_body_with_max ( response, MUXER_HTTP_MAX_LENGTH ) . await {
40+ Ok ( response_bytes) => {
41+ if status_code. is_success ( ) {
42+ return Ok ( response_bytes) ;
5143 }
52- Err ( e) => {
53- bail ! (
54- "Request failed with status: {} but decoding the response body failed: {}" ,
55- status_code,
56- e
57- ) ;
44+ bail ! (
45+ "Request failed with status: {status_code}, body: {}" ,
46+ String :: from_utf8_lossy( & response_bytes)
47+ )
48+ }
49+ Err ( e) => {
50+ if status_code. is_success ( ) {
51+ return Err ( e) . wrap_err ( "Failed to read response body" ) ;
5852 }
53+ Err ( e) . wrap_err ( format ! (
54+ "Request failed with status {status_code}, but decoding the response body failed"
55+ ) )
5956 }
6057 }
61- response_bytes
6258}
6359
6460/// Removes duplicate entries from a vector of BlsPublicKey
0 commit comments