@Test public void test() { final StatusType statusType = mock(StatusType.class); when(statusType.getFamily()).thenReturn(Status.Family.CLIENT_ERROR); final Response response = mock(Response.class); when(response.getStatus()).thenReturn(400); when(response.getStatusInfo()).thenReturn(statusType); final BadRequestException exception = new BadRequestException(response, new DecodeException((String)null, null)); try (final Response res = new BadRequestExceptionMapper().toResponse(exception)) { fail("Expected RuntimeException with ClassNotFoundException"); } catch (final RuntimeException e) { assertSame(ClassNotFoundException.class, e.getCause().getClass()); } }
@Override public Response toResponse(final BadRequestException exception) { try (final Response response = exception.getResponse()) { final StringBuilder builder = new StringBuilder("{\"status\":").append(response.getStatus()); final String message = exception.getMessage(); if (message != null) { final String prefix = "HTTP " + response.getStatus() + " "; builder.append(",\"message\":\"").append(message.startsWith(prefix) ? message.substring(prefix.length()) : message).append('"'); if (exception.getCause() instanceof DecodeException) builder.append(",\"cause\":\"").append(Strings.escapeForJava(exception.getCause().getMessage())).append('"'); } return Response.fromResponse(response).entity(builder.append('}').toString()).build(); } }
BadRequestExceptionMapper implements ExceptionMapper<BadRequestException> { @Override public Response toResponse(final BadRequestException exception) { try (final Response response = exception.getResponse()) { final StringBuilder builder = new StringBuilder("{\"status\":").append(response.getStatus()); final String message = exception.getMessage(); if (message != null) { final String prefix = "HTTP " + response.getStatus() + " "; builder.append(",\"message\":\"").append(message.startsWith(prefix) ? message.substring(prefix.length()) : message).append('"'); if (exception.getCause() instanceof DecodeException) builder.append(",\"cause\":\"").append(Strings.escapeForJava(exception.getCause().getMessage())).append('"'); } return Response.fromResponse(response).entity(builder.append('}').toString()).build(); } } }
BadRequestExceptionMapper implements ExceptionMapper<BadRequestException> { @Override public Response toResponse(final BadRequestException exception) { try (final Response response = exception.getResponse()) { final StringBuilder builder = new StringBuilder("{\"status\":").append(response.getStatus()); final String message = exception.getMessage(); if (message != null) { final String prefix = "HTTP " + response.getStatus() + " "; builder.append(",\"message\":\"").append(message.startsWith(prefix) ? message.substring(prefix.length()) : message).append('"'); if (exception.getCause() instanceof DecodeException) builder.append(",\"cause\":\"").append(Strings.escapeForJava(exception.getCause().getMessage())).append('"'); } return Response.fromResponse(response).entity(builder.append('}').toString()).build(); } }  }
BadRequestExceptionMapper implements ExceptionMapper<BadRequestException> { @Override public Response toResponse(final BadRequestException exception) { try (final Response response = exception.getResponse()) { final StringBuilder builder = new StringBuilder("{\"status\":").append(response.getStatus()); final String message = exception.getMessage(); if (message != null) { final String prefix = "HTTP " + response.getStatus() + " "; builder.append(",\"message\":\"").append(message.startsWith(prefix) ? message.substring(prefix.length()) : message).append('"'); if (exception.getCause() instanceof DecodeException) builder.append(",\"cause\":\"").append(Strings.escapeForJava(exception.getCause().getMessage())).append('"'); } return Response.fromResponse(response).entity(builder.append('}').toString()).build(); } }  @Override Response toResponse(final BadRequestException exception); }
BadRequestExceptionMapper implements ExceptionMapper<BadRequestException> { @Override public Response toResponse(final BadRequestException exception) { try (final Response response = exception.getResponse()) { final StringBuilder builder = new StringBuilder("{\"status\":").append(response.getStatus()); final String message = exception.getMessage(); if (message != null) { final String prefix = "HTTP " + response.getStatus() + " "; builder.append(",\"message\":\"").append(message.startsWith(prefix) ? message.substring(prefix.length()) : message).append('"'); if (exception.getCause() instanceof DecodeException) builder.append(",\"cause\":\"").append(Strings.escapeForJava(exception.getCause().getMessage())).append('"'); } return Response.fromResponse(response).entity(builder.append('}').toString()).build(); } }  @Override Response toResponse(final BadRequestException exception);  }