-
Notifications
You must be signed in to change notification settings - Fork 140
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
base: master
Are you sure you want to change the base?
Conversation
@@ -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)} |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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?
Can you comment on what this is trying to fix/improve? |
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. |
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())) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
omit return
keyword here.
No description provided.