BUG-5280: unwrap RuntimeRequestExceptions
[controller.git] / opendaylight / md-sal / cds-access-api / src / main / java / org / opendaylight / controller / cluster / access / concepts / RequestException.java
index ec519128414bc22c75ff53c6345223c7d33ab35d..4f2a0585da76c9afe04b0a5c744faf4c22138eba 100644 (file)
@@ -20,13 +20,23 @@ import javax.annotation.Nonnull;
 public abstract class RequestException extends Exception {
     private static final long serialVersionUID = 1L;
 
-    protected RequestException(final @Nonnull String message) {
+    protected RequestException(@Nonnull final String message) {
         super(Preconditions.checkNotNull(message));
     }
 
-    protected RequestException(final @Nonnull String message, final @Nonnull Exception cause) {
+    protected RequestException(@Nonnull final String message, @Nonnull final Throwable cause) {
         super(Preconditions.checkNotNull(message), Preconditions.checkNotNull(cause));
     }
 
     public abstract boolean isRetriable();
+
+    /**
+     * Unwraps the underlying failure. This method is overridden only in {@link RuntimeRequestException}.
+     *
+     * @return Underlying cause of the failure if exception is a {@link RuntimeRequestException}, or the exception
+     *         itself.
+     */
+    public Throwable unwrap() {
+        return this;
+    }
 }