Add RestconfCallback
[netconf.git] / restconf / restconf-common / src / main / java / org / opendaylight / restconf / common / errors / RestconfCallback.java
diff --git a/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/errors/RestconfCallback.java b/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/errors/RestconfCallback.java
new file mode 100644 (file)
index 0000000..d7bd8c2
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2023 PANTHEON.tech, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.restconf.common.errors;
+
+import com.google.common.util.concurrent.FutureCallback;
+import org.eclipse.jdt.annotation.NonNull;
+
+/**
+ * A {@link FutureCallback} tied to a {@link RestconfFuture}.
+ *
+ * @param <V> value type
+ */
+public abstract class RestconfCallback<V> implements FutureCallback<@NonNull V> {
+    @Override
+    public final void onFailure(final Throwable cause) {
+        onFailure(cause instanceof RestconfDocumentedException rde ? rde
+            : new RestconfDocumentedException("Unexpected failure", cause));
+    }
+
+    protected abstract void onFailure(@NonNull RestconfDocumentedException failure);
+}