@@ -475,18 +475,8 @@ async fn execute_for_other_user(
475
475
. send ( ctx. github . raw ( ) )
476
476
. await ;
477
477
478
- match res {
479
- Ok ( resp) => {
480
- if !resp. status ( ) . is_success ( ) {
481
- log:: error!(
482
- "Failed to notify real user about command: response: {:?}" ,
483
- resp
484
- ) ;
485
- }
486
- }
487
- Err ( err) => {
488
- log:: error!( "Failed to notify real user about command: {:?}" , err) ;
489
- }
478
+ if let Err ( err) = res {
479
+ log:: error!( "Failed to notify real user about command: {:?}" , err) ;
490
480
}
491
481
492
482
Ok ( Some ( output) )
@@ -591,7 +581,7 @@ impl<'a> MessageApiRequest<'a> {
591
581
self . recipient . url ( )
592
582
}
593
583
594
- pub async fn send ( & self , client : & reqwest:: Client ) -> anyhow:: Result < reqwest :: Response > {
584
+ pub async fn send ( & self , client : & reqwest:: Client ) -> anyhow:: Result < MessageApiResponse > {
595
585
let bot_api_token = env:: var ( "ZULIP_API_TOKEN" ) . expect ( "ZULIP_API_TOKEN" ) ;
596
586
597
587
#[ derive( serde:: Serialize ) ]
@@ -604,7 +594,7 @@ impl<'a> MessageApiRequest<'a> {
604
594
content : & ' a str ,
605
595
}
606
596
607
- Ok ( client
597
+ let resp = client
608
598
. post ( format ! ( "{}/api/v1/messages" , * ZULIP_URL ) )
609
599
. basic_auth ( & * ZULIP_BOT_EMAIL , Some ( & bot_api_token) )
610
600
. form ( & SerializedApi {
@@ -623,11 +613,30 @@ impl<'a> MessageApiRequest<'a> {
623
613
content : self . content ,
624
614
} )
625
615
. send ( )
626
- . await ?)
616
+ . await
617
+ . context ( "fail sending Zulip message" ) ?;
618
+
619
+ let status = resp. status ( ) ;
620
+
621
+ if !status. is_success ( ) {
622
+ let body = resp
623
+ . text ( )
624
+ . await
625
+ . context ( "fail receiving Zulip API response (when sending a message)" ) ?;
626
+
627
+ anyhow:: bail!( body)
628
+ }
629
+
630
+ let resp: MessageApiResponse = resp
631
+ . json ( )
632
+ . await
633
+ . context ( "fail receiving the JSON Zulip Api reponse (when sending a message)" ) ?;
634
+
635
+ Ok ( resp)
627
636
}
628
637
}
629
638
630
- #[ derive( serde:: Deserialize ) ]
639
+ #[ derive( Debug , serde:: Deserialize ) ]
631
640
pub struct MessageApiResponse {
632
641
#[ serde( rename = "id" ) ]
633
642
pub message_id : u64 ,
@@ -833,11 +842,6 @@ struct ResponseNotRequired {
833
842
response_not_required : bool ,
834
843
}
835
844
836
- #[ derive( serde:: Deserialize , Debug ) ]
837
- struct SentMessage {
838
- id : u64 ,
839
- }
840
-
841
845
#[ derive( serde:: Serialize , Debug , Copy , Clone ) ]
842
846
struct AddReaction < ' a > {
843
847
message_id : u64 ,
@@ -911,14 +915,10 @@ async fn post_waiter(
911
915
}
912
916
. send ( ctx. github . raw ( ) )
913
917
. await ?;
914
- let body = posted. text ( ) . await ?;
915
- let message_id = serde_json:: from_str :: < SentMessage > ( & body)
916
- . with_context ( || format ! ( "{:?} did not deserialize as SentMessage" , body) ) ?
917
- . id ;
918
918
919
919
for reaction in waiting. emoji {
920
920
AddReaction {
921
- message_id,
921
+ message_id : posted . message_id ,
922
922
emoji_name : reaction,
923
923
}
924
924
. send ( & ctx. github . raw ( ) )
0 commit comments