Fixing middleware JSON responses

pull/539/merge
Jordan Wright 2017-01-18 20:12:25 -06:00
parent c52981614a
commit b3cadcb01f
1 changed files with 3 additions and 2 deletions

View File

@ -73,6 +73,7 @@ func RequireAPIKey(handler http.Handler) http.HandlerFunc {
}
if ak == "" {
JSONError(w, 400, "API Key not set")
return
} else {
u, err := models.GetUserByAPIKey(ak)
if err != nil {
@ -101,8 +102,8 @@ func RequireLogin(handler http.Handler) http.HandlerFunc {
// JSONError returns an error in JSON format with the given
// status code and message
func JSONError(w http.ResponseWriter, c int, m string) {
w.WriteHeader(c)
w.Header().Set("Content-Type", "application/json")
cj, _ := json.MarshalIndent(models.Response{Success: false, Message: m}, "", " ")
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(c)
fmt.Fprintf(w, "%s", cj)
}