You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by "krisztina-zsihovszki (via GitHub)" <gi...@apache.org> on 2023/03/10 14:24:29 UTC

[GitHub] [nifi] krisztina-zsihovszki commented on a diff in pull request #7007: NIFI-4651 Add error message and code to PutSQL FlowFile attributes

krisztina-zsihovszki commented on code in PR #7007:
URL: https://github.com/apache/nifi/pull/7007#discussion_r1132444658


##########
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutSQL.java:
##########
@@ -836,7 +870,17 @@ boolean isFragmentedTransactionReady(final List<FlowFile> flowFiles, final Long
         return false;  // not enough FlowFiles for this transaction. Return them all to queue.
     }
 
+    private FlowFile addErrorAttributesToFlowFile(final ProcessSession session, FlowFile flowFile, final Exception exception) {
+        final Map<String, String> attributes = new HashMap<>();
+        attributes.put(ERROR_MESSAGE_ATTR, exception.getMessage());
 
+        if (exception instanceof SQLException) {
+            attributes.put(ERROR_CODE_ATTR, valueOf(((SQLException) exception).getErrorCode()));
+            attributes.put(ERROR_SQL_STATE_ATTR, valueOf(((SQLException) exception).getSQLState()));
+        }
+
+        return session.putAllAttributes(flowFile, attributes);

Review Comment:
   The method adds extra attributes to the FlowFile, it does not remove any existing attribute. (Added a check in unit tests to verify this.) 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org