@@ -224,7 +224,7 @@ impl<N: Network> RestQuery<N> {
224224 . with_context ( || format ! ( "Failed to fetch from {endpoint}" ) ) ?;
225225
226226 if response. status ( ) . is_success ( ) {
227- response. body_mut ( ) . read_json ( ) . with_context ( || "Failed to parse JSON response" )
227+ response. body_mut ( ) . read_json ( ) . with_context ( || format ! ( "Failed to parse JSON response from {endpoint}" ) )
228228 } else {
229229 let content_type = response
230230 . headers ( )
@@ -236,11 +236,16 @@ impl<N: Network> RestQuery<N> {
236236 // Convert returned error into an `anyhow::Error`.
237237 // Depending on the API version, the error is either encoded as a string or as a JSON.
238238 if content_type. contains ( "json" ) {
239- let error: RestError =
240- response. body_mut ( ) . read_json ( ) . with_context ( || "Failed to parse JSON error response" ) ?;
239+ let error: RestError = response
240+ . body_mut ( )
241+ . read_json ( )
242+ . with_context ( || format ! ( "Failed to parse JSON error response from {endpoint}" ) ) ?;
241243 Err ( error. parse ( ) . context ( format ! ( "Failed to fetch from {endpoint}" ) ) )
242244 } else {
243- let error = response. body_mut ( ) . read_to_string ( ) . with_context ( || "Failed to read error message" ) ?;
245+ let error = response
246+ . body_mut ( )
247+ . read_to_string ( )
248+ . with_context ( || format ! ( "Failed to read error message {endpoint}" ) ) ?;
244249 Err ( anyhow ! ( error) . context ( format ! ( "Failed to fetch from {endpoint}" ) ) )
245250 }
246251 }
@@ -256,10 +261,13 @@ impl<N: Network> RestQuery<N> {
256261 let response = reqwest:: get ( & endpoint) . await . with_context ( || format ! ( "Failed to fetch from {endpoint}" ) ) ?;
257262
258263 if response. status ( ) . is_success ( ) {
259- response. json ( ) . await . with_context ( || "Failed to parse JSON response" )
264+ response. json ( ) . await . with_context ( || format ! ( "Failed to parse JSON response from {endpoint}" ) )
260265 } else {
261266 // Convert returned error into an `anyhow::Error`.
262- let error: RestError = response. json ( ) . await . with_context ( || "Failed to parse JSON error response" ) ?;
267+ let error: RestError = response
268+ . json ( )
269+ . await
270+ . with_context ( || format ! ( "Failed to parse JSON error response from {endpoint}" ) ) ?;
263271 Err ( error. parse ( ) . context ( format ! ( "Failed to fetch from {endpoint}" ) ) )
264272 }
265273 }
0 commit comments