BadRequestExceptionMapper extends CandlepinExceptionMapper implements ExceptionMapper<BadRequestException> { @Override public final Response toResponse(final BadRequestException exception) { if (badQueryParamHandler.canHandle(exception)) { return badQueryParamHandler.getResponse(exception); } else { Map<String, String> map = VersionUtil.getVersionMap(); ResponseBuilder bldr = Response.status(Status.BAD_REQUEST) .type(determineBestMediaType()) .header(VersionUtil.VERSION_HEADER, map.get("version") + "-" + map.get("release")); String message = null; for (Throwable current = exception; current != null; current = current.getCause()) { message = current.getMessage(); } if (message == null || message.isEmpty()) { message = I18n.marktr("Bad Request"); } return bldr.entity(new ExceptionMessage(i18n.get().tr(message))).build(); } }  @Override final Response toResponse(final BadRequestException exception);  }
@Test public void extractIllegalValue() { rem = injector.getInstance(BadRequestExceptionMapper.class); String foo = "javax.ws.rs.SomeThing(\"paramName\") value is 'strVal' for"; BadRequestException bre = new BadRequestException(foo); Response r = rem.toResponse(bre); assertEquals(Status.BAD_REQUEST.getStatusCode(), r.getStatus()); verifyMessage(r, "strVal is not a valid value for paramName"); }
@Test public void emptyMessage() { rem = injector.getInstance(BadRequestExceptionMapper.class); BadRequestException bre = new BadRequestException(""); Response r = rem.toResponse(bre); assertEquals(Status.BAD_REQUEST.getStatusCode(), r.getStatus()); verifyMessage(r, "Bad Request"); }