@@ -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 ,
@@ -642,7 +651,7 @@ pub struct UpdateMessageApiRequest<'a> {
642
651
}
643
652
644
653
impl < ' a > UpdateMessageApiRequest < ' a > {
645
- pub async fn send ( & self , client : & reqwest:: Client ) -> anyhow:: Result < reqwest :: Response > {
654
+ pub async fn send ( & self , client : & reqwest:: Client ) -> anyhow:: Result < ( ) > {
646
655
let bot_api_token = env:: var ( "ZULIP_API_TOKEN" ) . expect ( "ZULIP_API_TOKEN" ) ;
647
656
648
657
#[ derive( serde:: Serialize ) ]
@@ -655,7 +664,7 @@ impl<'a> UpdateMessageApiRequest<'a> {
655
664
pub content : Option < & ' a str > ,
656
665
}
657
666
658
- Ok ( client
667
+ let resp = client
659
668
. patch ( & format ! (
660
669
"{}/api/v1/messages/{}" ,
661
670
* ZULIP_URL , self . message_id
@@ -667,7 +676,21 @@ impl<'a> UpdateMessageApiRequest<'a> {
667
676
content : self . content ,
668
677
} )
669
678
. send ( )
670
- . await ?)
679
+ . await
680
+ . context ( "failed to send Zulip API Update Message" ) ?;
681
+
682
+ let status = resp. status ( ) ;
683
+
684
+ if !status. is_success ( ) {
685
+ let body = resp
686
+ . text ( )
687
+ . await
688
+ . context ( "fail receiving Zulip API response (when updating the message)" ) ?;
689
+
690
+ anyhow:: bail!( body)
691
+ }
692
+
693
+ Ok ( ( ) )
671
694
}
672
695
}
673
696
@@ -833,30 +856,38 @@ struct ResponseNotRequired {
833
856
response_not_required : bool ,
834
857
}
835
858
836
- #[ derive( serde:: Deserialize , Debug ) ]
837
- struct SentMessage {
838
- id : u64 ,
839
- }
840
-
841
859
#[ derive( serde:: Serialize , Debug , Copy , Clone ) ]
842
860
struct AddReaction < ' a > {
843
861
message_id : u64 ,
844
862
emoji_name : & ' a str ,
845
863
}
846
864
847
865
impl < ' a > AddReaction < ' a > {
848
- pub async fn send ( self , client : & reqwest:: Client ) -> anyhow:: Result < reqwest :: Response > {
866
+ pub async fn send ( self , client : & reqwest:: Client ) -> anyhow:: Result < ( ) > {
849
867
let bot_api_token = env:: var ( "ZULIP_API_TOKEN" ) . expect ( "ZULIP_API_TOKEN" ) ;
850
868
851
- Ok ( client
869
+ let resp = client
852
870
. post ( & format ! (
853
871
"{}/api/v1/messages/{}/reactions" ,
854
872
* ZULIP_URL , self . message_id
855
873
) )
856
874
. basic_auth ( & * ZULIP_BOT_EMAIL , Some ( & bot_api_token) )
857
875
. form ( & self )
858
876
. send ( )
859
- . await ?)
877
+ . await ?;
878
+
879
+ let status = resp. status ( ) ;
880
+
881
+ if !status. is_success ( ) {
882
+ let body = resp
883
+ . text ( )
884
+ . await
885
+ . context ( "fail receiving Zulip API response (when adding a reaction)" ) ?;
886
+
887
+ anyhow:: bail!( body)
888
+ }
889
+
890
+ Ok ( ( ) )
860
891
}
861
892
}
862
893
@@ -911,14 +942,10 @@ async fn post_waiter(
911
942
}
912
943
. send ( ctx. github . raw ( ) )
913
944
. 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
945
919
946
for reaction in waiting. emoji {
920
947
AddReaction {
921
- message_id,
948
+ message_id : posted . message_id ,
922
949
emoji_name : reaction,
923
950
}
924
951
. send ( & ctx. github . raw ( ) )
0 commit comments