Bug 2731: Discard changes only when transaction exist.
[controller.git] / opendaylight / netconf / config-netconf-connector / src / main / java / org / opendaylight / controller / netconf / confignetconfconnector / operations / DiscardChanges.java
index dd2ceaec193bf3b55df22bd6d129c9f69f0e508f..1f70a1e52df63b62118e8c97af6b4107c9f068b8 100644 (file)
@@ -54,13 +54,15 @@ public class DiscardChanges extends AbstractConfigNetconfOperation {
     protected Element handleWithNoSubsequentOperations(Document document, XmlElement xml) throws NetconfDocumentedException {
         fromXml(xml);
         try {
-            this.transactionProvider.abortTransaction();
-        } catch (final IllegalStateException e) {
+            if (transactionProvider.getTransaction().isPresent()) {
+                this.transactionProvider.abortTransaction();
+            }
+        } catch (final RuntimeException e) {
             LOG.warn("Abort failed: ", e);
             final Map<String, String> errorInfo = new HashMap<>();
             errorInfo
                     .put(ErrorTag.operation_failed.name(),
-                            "Operation failed. Use 'get-config' or 'edit-config' before triggering 'discard-changes' operation");
+                            "Abort failed.");
             throw new NetconfDocumentedException(e.getMessage(), e, ErrorType.application, ErrorTag.operation_failed,
                     ErrorSeverity.error, errorInfo);
         }