code: protected StatusObject generateErrorResult(String code, Throwable error) {
          // Construct error object to return
          String message = "";
          while (error != null && error.getCause() != null) {
              error = error.getCause();
          }
          if (error != null && error.getMessage() != null) {
              message = error.getMessage();
          }
          StatusObject status = new StatusObject(code, "error", message);
          if (error instanceof ClientDetailsException) {
              // Return exception details to client
              status.setApplication(((ClientDetailsException) error).getParameters());
              if (((ClientDetailsException) error).includeStacktrace()) {
                  List<String> stack = new ArrayList<String>();
                  for (StackTraceElement element : error.getStackTrace()) {
                      stack.add(element.toString());
                  }
                  status.setAdditional("stacktrace", stack);
              }
          } else if (error != null) {
              status.setApplication(error.getClass().getCanonicalName());
              List<String> stack = new ArrayList<String>();
              for (StackTraceElement element : error.getStackTrace()) {
                  stack.add(element.toString());
              }
              status.setAdditional("stacktrace", stack);
          }
          return status;
      }
docs: Generate error object to return for given exception.
  
  @param code
  call
  @param error
  error
  @return status object