func SetError(w http.ResponseWriter, errOriginal error) {
	if errOriginal == nil {
		w.WriteHeader(http.StatusOK)
		return
	}
	err := errors.Cause(errOriginal)
	h := w.Header()
	h[HeaderErrors] = []string{err.Error()}
	switch err {
	case ErrTopicDoesNotExist, ErrTopicAlreadyExists:
		w.WriteHeader(http.StatusPreconditionFailed)
	case
		ErrInvalidHeaderSizes,
		ErrInvalidMessageID,
		ErrInvalidMessageLimit,
		ErrInvalidTopic,
		ErrInvalidBodyMissing,
		ErrInvalidBodyJSON,
		ErrInvalidWebsocket:
		w.WriteHeader(http.StatusBadRequest)
	case ErrNoContent:
		w.WriteHeader(http.StatusNoContent)
	case ErrClosed:
		w.WriteHeader(http.StatusServiceUnavailable)
	default:
		w.WriteHeader(http.StatusInternalServerError)
	}
	_, _ = w.Write([]byte(errOriginal.Error()))
}
SetError adds the error to the response header and body and sets the status code as needed
package headers
import (
	"bytes"
	"net/http"
	"strconv"
	"strings"
	"sync"
	"time"
	"unsafe"
	"github.com/pkg/errors"
)
const (
	HeaderErrors        = "X-Errors"
	HeaderSizes         = "X-Sizes"
	HeaderStartTime     = "X-Start-Time"
	HeaderEndTime       = "X-End-Time"
	HeaderFileName      = "X-File-Name"
	HeaderWatchTopics   = "X-Topics"
	HeaderConsumerGroup = "X-Consumer-Group"
	HeaderID            = "X-Id"
	HeaderLimit         = "X-Limit"
	Accept              = "Accept"
	ContentType         = "Content-Type"
	LastModified        = "Last-Modified"
)
const (
	errTopicDoesNotExist   = "topic does not exist"
	errTopicAlreadyExists  = "topic already exists"
	errInvalidHeaderSizes  = "invalid header: " + HeaderSizes
	errInvalidMessageID    = "invalid message id"
	errConsumerLockFailed  = "unable to get consumer offset"
	errInvalidMessageLimit = "invalid message limit"
	errInvalidTopic        = "invalid topic"
	errInvalidBodyMissing  = "invalid body: body cannot be empty"
	errInvalidBodyJSON     = "invalid body: invalid json entry"
	errInvalidWebsocket    = "invalid websocket"
	errNoContent           = "no content"
	errClosed              = "server closing"
	errProxyFailed         = "proxy failed"
)
var (
	ErrTopicDoesNotExist   = errors.New(errTopicDoesNotExist)
	ErrTopicAlreadyExists  = errors.New(errTopicAlreadyExists)
	ErrInvalidHeaderSizes  = errors.New(errInvalidHeaderSizes)
	ErrConsumerLockFailed  = errors.New(errConsumerLockFailed)
	ErrInvalidMessageID    = errors.New(errInvalidMessageID)
	ErrInvalidMessageLimit = errors.New(errInvalidMessageLimit)
	ErrInvalidTopic        = errors.New(errInvalidTopic)
	ErrInvalidBodyMissing  = errors.New(errInvalidBodyMissing)
	ErrInvalidBodyJSON     = errors.New(errInvalidBodyJSON)
	ErrInvalidWebsocket    = errors.New(errInvalidWebsocket)
	ErrNoContent           = errors.New(errNoContent)
	ErrClosed              = errors.New(errClosed)
	ErrProxyFailed         = errors.New(errProxyFailed)
)
var errMap = map[string]error{
	errTopicDoesNotExist:   ErrTopicDoesNotExist,
	errTopicAlreadyExists:  ErrTopicAlreadyExists,
	errInvalidHeaderSizes:  ErrInvalidHeaderSizes,
	errInvalidMessageID:    ErrInvalidMessageID,
	errConsumerLockFailed:  ErrConsumerLockFailed,
	errInvalidMessageLimit: ErrInvalidMessageLimit,
	errInvalidTopic:        ErrInvalidTopic,
	errInvalidBodyMissing:  ErrInvalidBodyMissing,
	errInvalidBodyJSON:     ErrInvalidBodyJSON,
	errInvalidWebsocket:    ErrInvalidWebsocket,
	errNoContent:           ErrNoContent,
	errClosed:              ErrClosed,
	errProxyFailed:         ErrProxyFailed,
}