signaller/internal/errors.go

27 lines
475 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, message string) {
2019-07-18 14:10:43 +00:00
w.Header().Set("Content-Type", "application/json")
if message != "" {
code.Message = message
}
w.WriteHeader(httpCode)
w.Write(code.JSON())
}
func NewError(code models.ApiError, message string) *models.ApiError {
2019-07-18 14:10:43 +00:00
if message != "" {
code.Message = message
}
return &code
}