@@ -154,6 +154,17 @@ pub struct SqsBatchResponse {
154154 pub other : serde_json:: Map < String , Value > ,
155155}
156156
157+ impl SqsBatchResponse {
158+ /// Add a failed message ID to the batch response
159+ pub fn add_failure ( & mut self , message_id : String ) -> ( ) {
160+ self . batch_item_failures . push ( BatchItemFailure {
161+ item_identifier : message_id,
162+ #[ cfg( feature = "catch-all-fields" ) ]
163+ other : serde_json:: Map :: new ( ) ,
164+ } ) ;
165+ }
166+ }
167+
157168#[ non_exhaustive]
158169#[ derive( Clone , Debug , Default , Deserialize , Eq , PartialEq , Serialize ) ]
159170#[ serde( rename_all = "camelCase" ) ]
@@ -335,4 +346,16 @@ mod test {
335346 let reparsed: SqsApiEventObj < CustStruct > = serde_json:: from_slice ( output. as_bytes ( ) ) . unwrap ( ) ;
336347 assert_eq ! ( parsed, reparsed) ;
337348 }
349+
350+ #[ test]
351+ #[ cfg( feature = "sqs" ) ]
352+ fn example_sqs_batch_response_add_failure ( ) {
353+ let mut response = SqsBatchResponse :: default ( ) ;
354+ response. add_failure ( "msg-1" . to_string ( ) ) ;
355+ response. add_failure ( "msg-2" . to_string ( ) ) ;
356+
357+ assert_eq ! ( response. batch_item_failures. len( ) , 2 ) ;
358+ assert_eq ! ( response. batch_item_failures[ 0 ] . item_identifier, "msg-1" ) ;
359+ assert_eq ! ( response. batch_item_failures[ 1 ] . item_identifier, "msg-2" ) ;
360+ }
338361}
0 commit comments