signaller/internal/errors.go
2019-08-03 19:19:18 +05:00

20 lines
406 B
Go

package internal
import (
"net/http"
"github.com/signaller-matrix/signaller/internal/models"
)
func errorResponse(w http.ResponseWriter, code models.ApiError, httpCode int, messageOverride string) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(httpCode)
if messageOverride != "" {
w.Write(models.NewError(code, messageOverride).JSON())
} else {
w.Write(code.JSON())
}
}