package server

import (
	"encoding/json"
	"net/http"

	"github.com/rs/zerolog/log"
)

func makeErrorResponse(w http.ResponseWriter, err error, statusCode int) {
	type ErrorMessage struct {
		Message string
	}

	w.Header().Add("Content-Type", "application/json")
	w.WriteHeader(statusCode)

	errResponse := &ErrorMessage{Message: err.Error()}
	if errE := json.NewEncoder(w).Encode(errResponse); errE != nil {
		log.Err(errE).Send()

		return
	}
}
