code: private void sendErrorJSON(HttpServletResponse response, int statusCode, String errorCode, String errorDescription) {
          final String error = "error";
          final String error_description = "error_description";
          try {
              if (errorCode != null) {
                  response.setStatus(statusCode);
                  response.setHeader(ClientConstants.REQ_CONTENT_TYPE_NAME,
                          "application/json;charset=UTF-8");
  
                  JSONObject responseJSON = new JSONObject();
                  responseJSON.put(error, errorCode);
                  if (errorDescription != null) {
                      responseJSON.put(error_description, errorDescription);
                  }
                  PrintWriter pw;
                  pw = response.getWriter();
                  pw.write(responseJSON.toString());
                  pw.flush();
              } else {
                  response.sendError(statusCode);
              }
          } catch (IOException e) {
              if (tc.isDebugEnabled())
                  Tr.debug(tc, "Internal error sending error message", e);
              try {
                  response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
              } catch (IOException ioe) {
                  if (tc.isDebugEnabled())
                      Tr.debug(tc, "yet another internal error, give up", ioe);
              }
          }
  
      }
docs: refactored from Oauth SendErrorJson.  Only usable for sending an http400.