func SendErrorResponse(writer http.ResponseWriter, err error, message string, statusCode int) {
	if statusCode == 0 {
		switch err.(type) {
		case *common.InvalidRequest:
			statusCode = http.StatusBadRequest
		case *storage.Error:
			statusCode = http.StatusInternalServerError
		case *storage.NotConnected:
			statusCode = http.StatusServiceUnavailable
		case *ignoredByHandler:
			statusCode = http.StatusConflict
		case *Error:
			statusCode = http.StatusNoContent
			message = ""
			err = nil
		default:
			statusCode = http.StatusInternalServerError
		}
	}
	writer.WriteHeader(statusCode)
	if message != "" || err != nil {
		writer.Header().Add("Content-Type", "Text/Plain")
		buffer := bytes.NewBufferString(message)
		if err != nil {
			buffer.WriteString(err.Error())
		}
		buffer.WriteString("\n")
		writer.Write(buffer.Bytes())
	}
}
SendErrorResponse common code to send HTTP error codes
package communications
import (
	"bytes"
	"net/http"
	"strings"
	"time"
	"github.com/open-horizon/edge-sync-service/common"
	"github.com/open-horizon/edge-sync-service/core/storage"
	"github.com/open-horizon/edge-utilities/logger"
	"github.com/open-horizon/edge-utilities/logger/log"
)
type Communicator interface {
	StartCommunication() common.SyncServiceError
	StopCommunication() common.SyncServiceError
	SendNotificationMessage(notificationTopic string, destType string, destID string, instanceID int64, dataID int64, metaData *common.MetaData) common.SyncServiceError
	SendFeedbackMessage(code int, retryInterval int32, reason string, metaData *common.MetaData, sendToOrigin bool) common.SyncServiceError
	SendErrorMessage(err common.SyncServiceError, metaData *common.MetaData, sendToOrigin bool) common.SyncServiceError
	Register() common.SyncServiceError
	RegisterAck(destination common.Destination) common.SyncServiceError
	HandleRegAck()
	RegisterAsNew(destination common.Destination) common.SyncServiceError
	RegisterNew() common.SyncServiceError
	Unregister() common.SyncServiceError
	SendPing() common.SyncServiceError
	GetData(metaData common.MetaData, offset int64) common.SyncServiceError
	SendData(orgID string, destType string, destID string, message []byte, chunked bool) common.SyncServiceError
	ResendObjects() common.SyncServiceError
	SendAckResendObjects(destination common.Destination) common.SyncServiceError
	UpdateOrganization(org common.Organization, timestamp time.Time) common.SyncServiceError
	DeleteOrganization(orgID string) common.SyncServiceError
	LockDataChunks(index uint32, metadata *common.MetaData)
	UnlockDataChunks(index uint32, metadata *common.MetaData)
}
type Error struct {
	message string
}
func (e *Error) Error() string {
	return e.message
}
type ignoredByHandler struct {
	message string
}
func (e *ignoredByHandler) Error() string {
	if e.message == "" {
		return "Ignored by notification handler"
	}
	return e.message
}
func isIgnoredByHandler(err error) bool {
	_, ok := err.(*ignoredByHandler)
	return ok
}
var Store storage.Storage
var Comm Communicator
var DestReqQueue *DestinationRequestQueue