@@ -1077,10 +1077,11 @@ private void invokeBatchErrorHandler(final ConsumerRecords<K, V> records,
10771077 @ SuppressWarnings (RAW_TYPES ) @ Nullable Producer producer , RuntimeException e ) {
10781078
10791079 if (this .batchErrorHandler instanceof ContainerAwareBatchErrorHandler ) {
1080- this .batchErrorHandler .handle (e , records , this .consumer , KafkaMessageListenerContainer .this .container );
1080+ this .batchErrorHandler .handle (decorateException (e ), records , this .consumer ,
1081+ KafkaMessageListenerContainer .this .container );
10811082 }
10821083 else {
1083- this .batchErrorHandler .handle (e , records , this .consumer );
1084+ this .batchErrorHandler .handle (decorateException ( e ) , records , this .consumer );
10841085 }
10851086 // if the handler handled the error (no exception), go ahead and commit
10861087 if (producer != null ) {
@@ -1243,18 +1244,6 @@ private void invokeErrorHandler(final ConsumerRecord<K, V> record,
12431244 @ SuppressWarnings (RAWTYPES ) @ Nullable Producer producer ,
12441245 Iterator <ConsumerRecord <K , V >> iterator , RuntimeException e ) {
12451246
1246- Exception toHandle = e ;
1247- if (toHandle instanceof ListenerExecutionFailedException ) {
1248- toHandle = new ListenerExecutionFailedException (toHandle .getMessage (), this .consumerGroupId ,
1249- toHandle .getCause ());
1250- }
1251- else {
1252- /*
1253- * TODO: in 2.3, wrap all exceptions (e.g. thrown by user implementations
1254- * of MessageListener) in LEFE with groupId. @KafkaListeners always throw
1255- * LEFE.
1256- */
1257- }
12581247 if (this .errorHandler instanceof RemainingRecordsErrorHandler ) {
12591248 if (producer == null ) {
12601249 processCommits ();
@@ -1264,17 +1253,33 @@ private void invokeErrorHandler(final ConsumerRecord<K, V> record,
12641253 while (iterator .hasNext ()) {
12651254 records .add (iterator .next ());
12661255 }
1267- ((RemainingRecordsErrorHandler ) this .errorHandler ).handle (toHandle , records , this .consumer ,
1256+ ((RemainingRecordsErrorHandler ) this .errorHandler ).handle (decorateException ( e ) , records , this .consumer ,
12681257 KafkaMessageListenerContainer .this .container );
12691258 }
12701259 else {
1271- this .errorHandler .handle (toHandle , record , this .consumer );
1260+ this .errorHandler .handle (decorateException ( e ) , record , this .consumer );
12721261 }
12731262 if (producer != null ) {
12741263 ackCurrent (record , producer );
12751264 }
12761265 }
12771266
1267+ private Exception decorateException (RuntimeException e ) {
1268+ Exception toHandle = e ;
1269+ if (toHandle instanceof ListenerExecutionFailedException ) {
1270+ toHandle = new ListenerExecutionFailedException (toHandle .getMessage (), this .consumerGroupId ,
1271+ toHandle .getCause ());
1272+ }
1273+ else {
1274+ /*
1275+ * TODO: in 2.3, wrap all exceptions (e.g. thrown by user implementations
1276+ * of MessageListener) in LEFE with groupId. @KafkaListeners always throw
1277+ * LEFE.
1278+ */
1279+ }
1280+ return toHandle ;
1281+ }
1282+
12781283 public void checkDeser (final ConsumerRecord <K , V > record , String headerName ) {
12791284 Header header = record .headers ().lastHeader (headerName );
12801285 if (header != null ) {
0 commit comments