@@ -186,12 +186,7 @@ impl GithubApiClient {
186
186
. await
187
187
{
188
188
Ok ( response) => {
189
- if let Err ( e) = response. error_for_status_ref ( ) {
190
- log:: error!( "Failed to post thread comment: {e:?}" ) ;
191
- if let Ok ( text) = response. text ( ) . await {
192
- log:: error!( "{text}" ) ;
193
- }
194
- }
189
+ Self :: log_response ( response, "Failed to post thread comment" ) . await ;
195
190
}
196
191
Err ( e) => {
197
192
log:: error!( "Failed to post thread comment: {e:?}" ) ;
@@ -227,11 +222,12 @@ impl GithubApiClient {
227
222
. await
228
223
{
229
224
Ok ( response) => {
230
- if let Err ( e) = response. error_for_status_ref ( ) {
231
- log:: error!( "Failed to get list of existing thread comments: {e:?}" ) ;
232
- if let Ok ( text) = response. text ( ) . await {
233
- log:: error!( "{text}" ) ;
234
- }
225
+ if !response. status ( ) . is_success ( ) {
226
+ Self :: log_response (
227
+ response,
228
+ "Failed to get list of existing thread comments" ,
229
+ )
230
+ . await ;
235
231
return Ok ( comment_url) ;
236
232
}
237
233
comments_url = Self :: try_next_page ( response. headers ( ) ) ;
@@ -264,7 +260,7 @@ impl GithubApiClient {
264
260
} ;
265
261
let req = Self :: make_api_request (
266
262
& self . client ,
267
- del_url. clone ( ) ,
263
+ del_url. as_str ( ) ,
268
264
Method :: DELETE ,
269
265
None ,
270
266
None ,
@@ -278,13 +274,12 @@ impl GithubApiClient {
278
274
. await
279
275
{
280
276
Ok ( result) => {
281
- if let Err ( e) = result. error_for_status_ref ( ) {
282
- log:: error!(
283
- "Failed to delete old thread comment {e:?}"
284
- ) ;
285
- if let Ok ( text) = result. text ( ) . await {
286
- log:: error!( "{text}" ) ;
287
- }
277
+ if !result. status ( ) . is_success ( ) {
278
+ Self :: log_response (
279
+ result,
280
+ "Failed to delete old thread comment" ,
281
+ )
282
+ . await ;
288
283
}
289
284
}
290
285
Err ( e) => {
@@ -336,7 +331,7 @@ impl GithubApiClient {
336
331
0 ,
337
332
)
338
333
. await
339
- . with_context ( || "Failed to get PR info" ) ?;
334
+ . with_context ( || format ! ( "Failed to get PR info from {}" , url . as_str ( ) ) ) ?;
340
335
let pr_info: PullRequestInfo = serde_json:: from_str ( & response. text ( ) . await ?)
341
336
. with_context ( || "Failed to deserialize PR info" ) ?;
342
337
@@ -390,7 +385,7 @@ impl GithubApiClient {
390
385
dismissal. await ?; // free up the `url` variable
391
386
let request = Self :: make_api_request (
392
387
& self . client ,
393
- url,
388
+ url. clone ( ) ,
394
389
Method :: POST ,
395
390
Some (
396
391
serde_json:: to_string ( & payload)
@@ -407,11 +402,8 @@ impl GithubApiClient {
407
402
. await
408
403
{
409
404
Ok ( response) => {
410
- if let Err ( e) = response. error_for_status_ref ( ) {
411
- log:: error!( "Failed to post a new PR review: {e:?}" ) ;
412
- if let Ok ( text) = response. text ( ) . await {
413
- log:: error!( "{text}" ) ;
414
- }
405
+ if !response. status ( ) . is_success ( ) {
406
+ Self :: log_response ( response, "Failed to post a new PR review" ) . await ;
415
407
}
416
408
}
417
409
Err ( e) => {
@@ -442,7 +434,10 @@ impl GithubApiClient {
442
434
)
443
435
. await ;
444
436
if response. is_err ( ) || response. as_ref ( ) . is_ok_and ( |r| !r. status ( ) . is_success ( ) ) {
445
- log:: error!( "Failed to get a list of existing PR reviews" ) ;
437
+ log:: error!(
438
+ "Failed to get a list of existing PR reviews: {}" ,
439
+ endpoint. as_str( )
440
+ ) ;
446
441
return Ok ( ( ) ) ;
447
442
}
448
443
let response = response. unwrap ( ) ;
@@ -481,11 +476,12 @@ impl GithubApiClient {
481
476
. await
482
477
{
483
478
Ok ( result) => {
484
- if let Err ( e) = result. error_for_status_ref ( ) {
485
- log:: error!( "Failed to dismiss outdated review: {e:?}" ) ;
486
- if let Ok ( text) = result. text ( ) . await {
487
- log:: error!( "{text}" ) ;
488
- }
479
+ if !result. status ( ) . is_success ( ) {
480
+ Self :: log_response (
481
+ result,
482
+ "Failed to dismiss outdated review" ,
483
+ )
484
+ . await ;
489
485
}
490
486
}
491
487
Err ( e) => {
0 commit comments