code: func HandleError(w http.ResponseWriter, err error) (code int) {
  	if err == nil {
  		return http.StatusOK
  	}
  	msg := err.Error()
  	httpCode := http.StatusInternalServerError
  
  	// If it is recognized as HttpError emitted from cfssl,
  	// we rewrite the status code accordingly. If it is a
  	// cfssl error, set the http status to StatusBadRequest
  	switch err := err.(type) {
  	case *errors.HTTPError:
  		httpCode = err.StatusCode
  		code = err.StatusCode
  	case *errors.Error:
  		httpCode = http.StatusBadRequest
  		code = err.ErrorCode
  		msg = err.Message
  	}
  
  	response := NewErrorResponse(msg, code)
  	jsonMessage, err := json.Marshal(response)
  	if err != nil {
  		log.Errorf("Failed to marshal JSON: %v", err)
  	} else {
  		msg = string(jsonMessage)
  	}
  	http.Error(w, msg, httpCode)
  	return code
  }
docs: // HandleError is the centralised error handling and reporting.