Browse Source

Middleware now returns JSON error message

pull/24/head
Jordan 7 years ago
parent
commit
c349860878
1 changed files with 6 additions and 1 deletions
  1. +6
    -1
      middleware/middleware.go

+ 6
- 1
middleware/middleware.go View File

@ -1,6 +1,8 @@
package middleware
import (
"encoding/json"
"fmt"
"net/http"
ctx "github.com/gorilla/context"
@ -78,5 +80,8 @@ func RequireLogin(handler http.Handler) http.HandlerFunc {
}
func JSONError(w http.ResponseWriter, c int, m string) {
http.Error(w, m, c)
w.WriteHeader(c)
w.Header().Set("Content-Type", "application/json")
cj, _ := json.MarshalIndent(models.Response{Success: false, Message: m}, "", " ")
fmt.Fprintf(w, "%s", cj)
}

Loading…
Cancel
Save