Browse Source

Fixing middleware JSON responses

pull/539/merge
Jordan Wright 4 years ago
parent
commit
b3cadcb01f
1 changed files with 3 additions and 2 deletions
  1. +3
    -2
      middleware/middleware.go

+ 3
- 2
middleware/middleware.go 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)
}

Loading…
Cancel
Save