protected static void handleExceptionEnd(Throwable t, String message, boolean read) {
Response.Status status = read
? Response.Status.BAD_REQUEST : Response.Status.INTERNAL_SERVER_ERROR;
Response r = Response.status(status)
.type(MediaType.TEXT_PLAIN).entity(message).build();
throw read ? new BadRequestException(r, t) : new InternalServerErrorException(r, t);
}