Middleware now returns JSON error message

pull/24/head
Jordan 2014-06-01 23:14:05 -05:00
parent 31aa5614a0
commit c349860878
1 changed files with 6 additions and 1 deletions

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)
}