Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added error json response for broker endpoints #302

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/scala/main/ly/stealth/mesos/kafka/cli/Cli.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should be able to omit the type annotation here.

throw new IOException(connection.getResponseCode + " - " + errorMessage)
}
else throw e
}
}
} finally {
connection.disconnect()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

omit return keyword here.

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
}
}