signaller/internal/errors.go

20 lines
406 B
Go
Raw Permalink Normal View History

package internal
2019-07-18 14:10:43 +00:00
import (
"net/http"
2019-08-03 14:19:18 +00:00
"github.com/signaller-matrix/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
}
}