signaller/internal/errors.go

20 lines
397 B
Go
Raw Normal View History

package internal
2019-07-18 14:10:43 +00:00
import (
"net/http"
"github.com/nxshock/signaller/internal/models"
2019-07-18 14:10:43 +00:00
)
func errorResponse(w http.ResponseWriter, code models.ApiError, httpCode int, messageOverride string) {
2019-07-18 14:10:43 +00:00
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(httpCode)
if messageOverride != "" {
w.Write(models.NewError(code, messageOverride).JSON())
} else {
w.Write(code.JSON())
2019-07-18 14:10:43 +00:00
}
}