diff --git a/src/scala/main/ly/stealth/mesos/kafka/cli/Cli.scala b/src/scala/main/ly/stealth/mesos/kafka/cli/Cli.scala index 0b189df..305bb7a 100644 --- a/src/scala/main/ly/stealth/mesos/kafka/cli/Cli.scala +++ b/src/scala/main/ly/stealth/mesos/kafka/cli/Cli.scala @@ -21,6 +21,7 @@ import java.io._ import java.net.{HttpURLConnection, URL, URLEncoder} import java.util import java.util.Properties +import com.google.common.io.CharStreams import joptsimple.{BuiltinHelpFormatter, OptionException, OptionParser, OptionSet} import ly.stealth.mesos.kafka._ import net.elodina.mesos.util.Strings @@ -126,9 +127,13 @@ trait CliUtils try { response = Source.fromInputStream(connection.getInputStream).getLines().mkString} catch { - case e: IOException => - if (connection.getResponseCode != 200) throw new IOException(connection.getResponseCode + " - " + connection.getResponseMessage) + case e: IOException => { + if (connection.getResponseCode != 200) { + val errorMessage:String = CharStreams.toString(new InputStreamReader(connection.getErrorStream())) + throw new IOException(connection.getResponseCode + " - " + errorMessage) + } else throw e + } } } finally { connection.disconnect() diff --git a/src/scala/main/ly/stealth/mesos/kafka/scheduler/http/api/BrokerApi.scala b/src/scala/main/ly/stealth/mesos/kafka/scheduler/http/api/BrokerApi.scala index c814d9b..526f127 100644 --- a/src/scala/main/ly/stealth/mesos/kafka/scheduler/http/api/BrokerApi.scala +++ b/src/scala/main/ly/stealth/mesos/kafka/scheduler/http/api/BrokerApi.scala @@ -68,7 +68,7 @@ trait BrokerApiComponentImpl extends BrokerApiComponent { Response.ok(BrokerStatusResponse(brokerNodes)) .build() case Failure(e) => - Response.status(Response.Status.BAD_REQUEST).build() + return Status.BadRequest(e.getMessage) } } diff --git a/src/scala/main/ly/stealth/mesos/kafka/scheduler/http/api/Model.scala b/src/scala/main/ly/stealth/mesos/kafka/scheduler/http/api/Model.scala index a056c95..f9b563f 100644 --- a/src/scala/main/ly/stealth/mesos/kafka/scheduler/http/api/Model.scala +++ b/src/scala/main/ly/stealth/mesos/kafka/scheduler/http/api/Model.scala @@ -18,6 +18,7 @@ package ly.stealth.mesos.kafka.scheduler.http.api import javax.ws.rs.core.Response import javax.ws.rs.core.Response.StatusType +import ly.stealth.mesos.kafka.HttpErrorResponse import net.elodina.mesos.util.{Constraint, Strings} import scala.collection.JavaConverters._ import scala.collection.mutable @@ -37,6 +38,6 @@ object Status { override def getFamily: Response.Status.Family = Response.Status.BAD_REQUEST.getFamily } object BadRequest { - def apply(reason: String) = Response.status(new BadRequest(reason)).build() + def apply(reason: String) = Response.status(new BadRequest(reason)).entity(HttpErrorResponse(400, reason)).build() } } \ No newline at end of file