You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2023/06/23 14:53:50 UTC

[camel] 17/17: (chores) camel-kafka: do not catch Throwable

This is an automated email from the ASF dual-hosted git repository.

orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 57a0d98c76e85dfe9551df69a6f2f86a429b774a
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Fri Jun 23 14:56:19 2023 +0200

    (chores) camel-kafka: do not catch Throwable
---
 .../org/apache/camel/component/kafka/KafkaProducer.java     | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/KafkaProducer.java b/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/KafkaProducer.java
index 95afbde2960..73e02d323f1 100755
--- a/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/KafkaProducer.java
+++ b/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/KafkaProducer.java
@@ -550,12 +550,13 @@ class KafkaTransactionSynchronization extends SynchronizationAdapter {
                 LOG.debug("Commit kafka transaction {} with exchange {}", transactionId, exchange.getExchangeId());
                 kafkaProducer.commitTransaction();
             }
-        } catch (Throwable t) {
-            exchange.setException(t);
-            if (!(t instanceof KafkaException)) {
-                LOG.warn("Abort kafka transaction {} with exchange {} due to {} ", transactionId, exchange.getExchangeId(), t);
-                kafkaProducer.abortTransaction();
-            }
+        } catch (KafkaException e) {
+            exchange.setException(e);
+        } catch (Exception e) {
+            exchange.setException(e);
+            LOG.warn("Abort kafka transaction {} with exchange {} due to {} ", transactionId, exchange.getExchangeId(),
+                    e.getMessage(), e);
+            kafkaProducer.abortTransaction();
         } finally {
             exchange.getUnitOfWork().endTransactedBy(transactionId);
         }