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

Conversation

bjoel
Copy link

@bjoel bjoel commented May 5, 2017

No description provided.

@@ -440,7 +440,7 @@ trait BrokerCli {

val json =
try { sendRequestObj[HttpLogResponse]("/broker/log", params) }
catch { case e: IOException => throw new Error("" + e) }
catch { case e: IOException =>throw new Error("" + e)}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: spacing

if (connection.getResponseCode != 200) throw new IOException(connection.getResponseCode + " - " + connection.getResponseMessage)
case e: IOException => {
if (connection.getResponseCode != 200) {
val br = new BufferedReader(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 can use guava's CharStreams.toString method here instead of rolling your own.

@@ -68,7 +68,7 @@ trait BrokerApiComponentImpl extends BrokerApiComponent {
Response.ok(BrokerStatusResponse(brokerNodes))
.build()
case Failure(e) =>
Response.status(Response.Status.BAD_REQUEST).build()
Response.status(Response.Status.BAD_REQUEST).entity(HttpErrorResponse(400, e.getMessage())).build()
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you just refactor Status.BadRequest(...) to do this instead of copy/pasting it to each place it's used?

@steveniemitz
Copy link
Contributor

Can you comment on what this is trying to fix/improve?

@bjoel
Copy link
Author

bjoel commented May 10, 2017

Apologies for the late reply. This commit changes the error responses within the broker endpoints to return JSON values. Currently we have a service hitting these endpoints and when something goes wrong (i.e attempting to remove a broker which is currently running) HTML is returned. It is more helpful to return JSON so that our service can interpret the response and react appropriately.

@steveniemitz
Copy link
Contributor

Cool, seems good to me. Have you tested the backwards-compat case with an old client -> new server (and vis versa)?

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.

@@ -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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants