diff --git a/src/main/java/io/cryostat/targets/TargetConnectionManager.java b/src/main/java/io/cryostat/targets/TargetConnectionManager.java index 17b7791f2..b6d6c86b6 100644 --- a/src/main/java/io/cryostat/targets/TargetConnectionManager.java +++ b/src/main/java/io/cryostat/targets/TargetConnectionManager.java @@ -30,6 +30,7 @@ import java.util.concurrent.Executor; import java.util.concurrent.Semaphore; +import javax.management.InstanceNotFoundException; import javax.management.remote.JMXServiceURL; import javax.security.sasl.SaslException; @@ -200,6 +201,8 @@ public Uni executeConnectedTaskUni(Target target, ConnectedTask task) .transform(t -> unwrapNestedException(RuntimeException.class, t)) .onFailure() .invoke(logger::warn) + .onFailure(this::isInstanceNotFoundFailure) + .transform(t -> new HttpException(400, t)) .onFailure(this::isJmxAuthFailure) .transform(t -> new HttpException(427, t)) .onFailure(this::isJmxSslFailure) @@ -235,6 +238,8 @@ public Uni executeDirect( .transform(t -> unwrapNestedException(RuntimeException.class, t)) .onFailure() .invoke(logger::warn) + .onFailure(this::isInstanceNotFoundFailure) + .transform(t -> new HttpException(400, t)) .onFailure(this::isJmxAuthFailure) .transform(t -> new HttpException(427, t)) .onFailure(this::isJmxSslFailure) @@ -458,6 +463,15 @@ private boolean isServiceTypeFailure(Throwable t) { && ExceptionUtils.indexOfType(e, SocketTimeoutException.class) >= 0; } + /** Check if the exception happened because an MBean was not found */ + private boolean isInstanceNotFoundFailure(Throwable t) { + if (!(t instanceof Exception)) { + return false; + } + Exception e = (Exception) t; + return ExceptionUtils.indexOfType(e, InstanceNotFoundException.class) >= 0; + } + @Name("io.cryostat.targets.TargetConnectionManager.TargetConnectionOpened") @Label("Target Connection Opened") @Category("Cryostat")