Skip to content

Commit

Permalink
return bad request to customers if the http response code starts with…
Browse files Browse the repository at this point in the history
… 4 (#1222)

* return bad request to customers if the http response code starts with 4

* use Response.Status.Family.CLIENT_ERROR to check

* Update deploy-service/teletraanservice/src/main/java/com/pinterest/teletraan/exception/GenericExceptionMapper.java

Co-authored-by: Tyler Ouyang <[email protected]>

---------

Co-authored-by: Tyler Ouyang <[email protected]>
  • Loading branch information
liyaqin1 and tylerwowen committed Jul 25, 2023
1 parent 8180a48 commit 440f8c8
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@ public Response toResponse(Throwable t) {
PrintWriter pw = new PrintWriter(sw);
t.printStackTrace(pw);
sb.append("\n").append(sw.toString());
return Response.serverError().entity(sb.toString()).build();
final Response response = ((WebApplicationException) t).getResponse();
Response.Status.Family family = response.getStatusInfo().getFamily();
if (family.equals(Response.Status.Family.CLIENT_ERROR)) {
return Response.status(response.getStatus()).entity(sb.toString()).build();
} else {
return Response.serverError().entity(sb.toString()).build();
}
}
} else if (t instanceof ConstraintViolationException) {
StringBuilder sb = new StringBuilder();
Expand Down

0 comments on commit 440f8c8

Please sign in to comment.