Skip to content

Conversation

bjoel
Copy link

@bjoel bjoel commented May 5, 2017

No description provided.

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.

.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 bjoel closed this May 10, 2017
@bjoel bjoel reopened this May 10, 2017
@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.

.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