2019-07-19 07:39:53 +00:00
|
|
|
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
|
|
|
)
|
|
|
|
|
2019-08-03 06:46:57 +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)
|
|
|
|
|
2019-08-03 06:46:57 +00:00
|
|
|
if messageOverride != "" {
|
|
|
|
w.Write(models.NewError(code, messageOverride).JSON())
|
|
|
|
} else {
|
|
|
|
w.Write(code.JSON())
|
2019-07-18 14:10:43 +00:00
|
|
|
}
|
|
|
|
}
|