public static Response buildMessage(int httpCode, Map<String, Object> params,
                    String msg) {
    HashMap<String, Object> err = new HashMap<String, Object>();
    err.put("error", msg);
    if (params != null) {
      err.putAll(params);
    }

    String json = "\"error\"";
    try {
      json = new ObjectMapper().writeValueAsString(err);
    } catch (IOException e) {
    }

    return Response.status(httpCode)
      .entity(json)
      .type(MediaType.APPLICATION_JSON)
      .build();
  }
Simple exception that will return a json error payload if thrown
from a JAX web server.  We skip using WebApplicationException and
instead map our own so that Jersey doesn't log our exceptions as
error in the output log.  See SimpleExceptionMapper.
hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/SimpleWebException.java